How does the __block specifier work?

I can specify a variable on the stack with the specifier __block, and then I can change it in the block. I'm just wondering, behind the scenes, what's going on? (If the block is executed in the future, then the stack can be cleared)

+3
source share
1 answer

When a block that refers to a variable __blockis copied, the variable is moved to the heap. This means that all the code that refers to it must come by indirect means, mainly a pointer, so that when it moves from the stack to the heap, these links can switch along with it.

This is documented here .

+4
source

All Articles