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

Chapter 9: Memory Management > The Rules of Cocoa Memory Management

The Rules of Cocoa Memory Management

Now you've seen it all: retain, release, and autorelease. Cocoa has a number of memory management conventions. They're pretty simple rules, and they're applied consistently throughout the toolkit.

NOTE

Forgetting these rules is a common mistake, as is trying to make them too complicated. If you find yourself scattering retains and releases around aimlessly, hoping to fix some bug, you don't understand the rules. That means it's time to slow down, take a deep breath, maybe go get a snack, and read them again.

Here are the rules:

  • When you create an object using new, alloc, or copy, the object has a retain count of 1. You are responsible for sending the object a release or autorelease message when you're done with it. That way, it gets cleaned up when its useful life is over.

  

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