I can specify an a variable on stack with a __block specifier and then I am able to modify it in a block. I am just wondering, behind the scenes what happens? (If the block is executed sometime in the future, then the stack might be cleared)
I can specify an a variable on stack with a __block specifier and then
Share
When a block which references a
__blockvariable is copied, the variable is moved to the heap. This means that all code which references it has to do so through an indirect means, basically a pointer, so that, when it moves from the stack to the heap, those references can switch along with it.This is documented here.