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

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!

Memory Management

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!

Recap

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!

Do You Have Any Tips For Working With Memory?

Please tell us know by commenting below!

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

  1. iPhoneKicks.com October 20, 2009 at 4:53 am #

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

    You’ve been kicked (a good thing) – Trackback from iPhoneKicks.com – iPhone SDK links, community driven…

Leave a Reply

Affiliate Policy Disclosure

Switch to our mobile site