• Like all local variables, a non-static block exists on the stack and will be popped from the stack, like any other local variable which has not been declared static.
• Block_copy() copies the block from the stack onto the heap, where all malloc instances exist. And like all new/copy methods, Block_copy() returns a heap allocated object with a retain count of 1. A block is an objectiveC object but doesNot conform like a normal object. Therefore, there should be no difference between Block_Release() and the objective release method.
• This example uses the copy method of a block instance. Because assigning the result of a Block_copy() to an id requires a type cast that I doNot want to get wrong. The copy method allows the block variable to be assigned directly to an id.
- (void) setupStoredBlock
{
int zStackLocalVariable = 42;
iHeapAllocatedVariable = [^int(int aMore){ return zStackLocalVariable + aMore; } copy];
}
• To declare an object static is to require it to be physically allocated with the code itself. A block which is declared static is compiler prohibited from accessing variables outside of its own scope. Due to the requirements of a static block declaration, I assume that the block on the stack is somehow different from the block which is in the heap.
• A block is an objective c object whose class whose class name and other associated information I have not yet attempted to retrieve, but, like Protocol, Object and other hidden objectiveC classes, it does not conform to NSObject. Like all objectiveC objects, however, it must conform to retain/release. ARC extends retain/release equivalencies into Core Foundation objects as well, and probably, if not now, then eventually, into malloc/free allocations.
• I await the true motivation for a thorough exploration of mikeash.com, as apple likes to keep us all on some hyper-theoritical plane of little physical significance, even though all that is significant is physical.
ARC and blocks also discussed here