Here Is A Little Help To Understand Memory Management on the iPhone

Matthew Campbell, October 19th, 2009

Memory management is a problem that vexes most iPhone developers. When you get it right everything runs great, but when you get it wrong you iPhone app can leak memory or crash!

This is an important and big topic, but today I want to focus on one memory works during a typical code example that you would see on this website. That is, I would like you to understand what is happening with memory with an object that is added to a view controller’s subview collection.

This image is something that I put together that I hope will help you with this

Here is me on a video (Part One) explaining how memory is working here:

Here is another video (Part Two) since the first one was cut off!

Using alloc and adding an object to a collection (like our view’s subview collection) both increase your retain count by one. Once the system is completely finished with your object the retain count must be at zero or you will get a memory leak. But, be careful though because if you release your object too soon and the system needs it your app will crash!

Please tell us know by commenting below!