There are three types of blocks, which you can see by calling the class method or isa pointer. They are all derived from the NSBlock type
__NSGlobalBlock__ (_NSConcreteGlobalBlock)
__NSStackBlock__ (_NSConcreteStackBlock)
__NSMallocBlock__ (_NSConcreteMallocBlock)
Distinguish between:
-
Access the block of the auto variable –> __NSStackBlock___ stored in the stack;
-
Block without access to the auto variable –> __NSGlobalBlock__ stored in the data segment; ⚠️ : __NSStackBlock___ is stored on the stack, the potential danger is that it can be destroyed at any time. So in an ARC environment, blocks are automatically copied once, converting them to __NSMallocBlock__ stored on the heap.
-
Each type of block calls copy as follows: