Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Part III: Advanced Concepts > Garbage Collection

15. Garbage Collection

A typical running Objective-C program continually allocates new objects. Most of these objects are needed only temporarily; there is no need for them to remain valid until the program terminates. If the program doesn’t return the bytes used for the unneeded objects, the program’s memory footprint continues to grow and its performance suffers. The previous chapter covered reference counted memory, a manual system for managing memory. This chapter covers garbage collection, an automatic system for managing memory, which was added to Objective-C in Mac OS X Leopard (v 10.5). Garbage collection is not available on iOS.

When you use garbage collection for your memory management, a separate thread, called the garbage collector, runs periodically. The garbage collector examines your program’s memory, determines which objects are in use, and deallocates any objects that are not being used.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial