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?"