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 15. Blocks and Grand Central > Managing Memory with Blocks

Managing Memory with Blocks

From: blockMemory.m

5 __block int counter;
6 int(^block)(void) =
7   ^(void) { return counter++; };
8 block = [block retain];
9 _Block_release(block);

Memory management in Cocoa traditionally uses reference counting. Blocks work in the same way. There are two functions controlling the reference count of a block. The _Block_copy() function increases its reference count, while the _Block_release() function decreases it.


  

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