Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
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.