Chapter 13. Getting a Handle on Memory Management

In This Chapter

  • Understanding memory management

  • Finding potential memory leaks

  • Managing memory

  • Memory management for arrays and autoreleased objects

  • Using the garbage collector

  • Knowing the important memory management rules

In Chapter 12, I explain about object allocation and initialization. You start with alloc and init. It is alloc, if you remember, that sets aside some memory for the object and returns back a pointer to that memory. This is important to keep in mind, because once you create these new objects, you become responsible for managing them.

Managing the memory allocated for your objects can be one of the few real hassles in programming with Objective-C. And although a new feature in Objective-C 2.0, garbage collection, makes Mac OS X programming easier, it isn't available on the iPhone. But a word to the wise: Even if you want to program the Mac using only Objective-C 2.0 and garbage collection, read through this chapter anyway because it really will help solidify your understanding of pointers and objects and what gets passed when you include objects as arguments in messages.

Warning

Memory management is not glamorous, but it trumps cool in an application. In fact, memory management is probably the single most vexing thing about iPhone and Mac programming. It has made countless programmers crazy, and I can't stress enough how important it is to build memory management into your code from the start. Take it from me, retrofitting ...

Get Objective-C® For Dummies® now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.