O'Reilly logo

Cocoa Programming for Mac OS X, Third Edition by Aaron Hillegass

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 31. Garbage Collection

As long as you use only Objective-C objects, the garbage collector will do exactly what you want, without your needing to think about it. However, as soon as you start to malloc C data types and Core Foundation structures, you will need to be a bit more circumspect.

When the garbage collector runs, it is looking for unreachable objects. You can think of the objects in your applications as a directed graph: This object knows that object; it knows those objects; and they know those other objects. So, the garbage collector starts with the pointers on the stack and the global variables and wanders this directed graph until it has recorded every “reachable” object. The unreachable objects are deallocated. See Figure 31.1 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required