Search code examples
iphonexcodedealloc

Best memory management routine


I am writing an iPhone application, and now it is time to start cleaning up memory.

By a better programmer than myself, i was told that each time I perform a alloc, that I should dealloc the memory at the end of the module.

Is this statement that each time there is a alloc, that there should be a removal in the dealloc section of the .m file??

thanks tony


Solution

  • You might want to read up on the memory management guides on the Apple developer site. Basically you need to have a release or autorelease for every new, copy, or alloc you use. But the release ideally should be in the function that called new, copy, or alloc, not in your dealloc function. dealloc should only be used for releasing objects that were retained in the @property section of your header file.