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
  • PrintPrint
Share this Page URL
Help

3. Objective-C for iOS: Email needs vari... > Auto-generated accessors also handle...

Auto-generated accessors also handle memory management

Objective-C under iOS doesn’t have a garbage collector and instead uses a mechanism called reference counting. That involves keeping up with how many references there are to an object, and only freeing it up when the count drops to zero (it’s no longer being used). You can think of this as object-ownership. An object can have more than one owner, and as long as it has at least one, it continues to exist. If an object doesn’t have any owners left (its retain count hits 0), it’s freed and cleaned up.

When using properties, the compiler handles it for us. The properties we’ve declared so far have all used the retain attribute. When the compiler generates a setter for that property, it will properly handle memory management for us, like this:


  

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