refine memory management