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

Autorelease

Because of its name, you might think that autorelease is something like ARC. But it is not. It is more like “automatic variable” in the C language.7

Let’s start by reviewing what automatic variable is in C. We then look at the source code of GNUstep to understand how autorelease works, followed by Apple’s implementation of autorelease.

Automatic Variables

An automatic variable is a lexically scoped variable, which is disposed of automatically when the execution leaves the scope.

{
    int a;
}

/*
   * Because the variable scope is left,
   * auto variable 'int a' is disposed of and can't be accessed anymore.
   */

With autorelease, you can use objects in the same manner as automatic variables, meaning that when execution leaves a code block, the “release” method is called on the object automatically. You can control the block itself as well.


  

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