Refactor RunMemoryProfiling.