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

Chapter 14. Reference Counting > When Retain Counts Go Bad

When Retain Counts Go Bad

Reference counting depends on following the rules and balancing each object creation and retain message with an appropriate release or autorelease message. What happens if you make a mistake? Under-releasing an object causes a memory leak. The object is not deallocated when it should be, and its memory is never returned to the heap.

The results of over-releasing are more immediate and dire. If you send an object an extra release message, or send a release message to an object that you do not own, one release message causes the object to be deallocated. When the program sends the next release message, it is sending a message to a deallocated object. The result is usually a crash. This type of problem can be difficult to hunt down if the correct release and the spurious release are sent in widely separated sections of the code.


  

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


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint