Reorganize memory management related code.