In Objective-C we know that blocks have 3 implementations in runtime.
NSGlobalBlock
- that is singleton in runtime, and it is created in case we don't use values of stack variables.NSStackBlock
- that is not singleton, and it is allocated on stack (not on heap), and it is created when we use some stack variables.NSMallocBlock
- that is allocated on heap, and that is used when we want to store Blocks as ivar or property of some Class, or anywhere in heap f.e.@property (nonatomic, copy) MyBlockType myBlock;
or when we useBlock_copy()
function. It is really important because NSMallocBlock retains objects from context, and this fact can create some owning cycles, if we do not use blocks correct.
So, my question is: "Where can I find the full explanation C++ lambdas runtime, and how they are processed by Compiler? Or could you explain that? Is there any specific issues with memory management using C++ lambdas? Where lambdas are allocated, on heap or on stack?"
NSGlobalBlock
is for blocks that are not closures, i.e. that don't capture any local variables from an outside scope. "and it is created when we use _block modifiers for some stack variables." No. Again, it is for any blocks that are closures, i.e. that use a local variable from an outside scope. It doesn't have to a__block
variable. – newacct