Download Garbage Collection Programming Guide (Retired
Transcript
Architecture High-Level Architecture High-Level Architecture The garbage collector is implemented as a reusable library (called “auto”). The Objective-C runtime is a client of the library. TextEdit Terminal Xcode Application Kit Foundation Core Foundation Objective-C Runtime auto The collector does not scan all areas of memory (see Figure 1 (page 21)). The stack and global variables are always scanned; the malloc zone is never scanned. The collector provides a special area of memory known as the auto zone from which all garbage-collected blocks of memory are dispensed. You can use the collector to allocate blocks of memory in the auto zone—these blocks are then managed by the collector. How the Garbage Collector Works The mechanism of garbage collection is fairly simple to describe although the implementation is more complicated. The garbage collector's goal is to form a set of reachable objects that constitute the "valid" objects in your application. When a collection is initiated, the collector initializes the set with all known root objects such as stack-allocated and global variables (for example, the NSApplication shared instance). The collector then recursively follows strong references from these objects to other objects, and adds these to the set. All Retired Document | 2012-07-23 | Copyright © 2012 Apple Inc. All Rights Reserved. 20