memory consumption cleanup and before after callbacks