update memory cleanup routine