0

According to the Apple documentation

When a block is copied, it creates strong references to object variables used within the block. If you use a block within the implementation of a method:

If you access an instance variable by reference, a strong reference is made to self; If you access an instance variable by value, a strong reference is made to the variable.

I want to understand how a block manages to do this internally. How does it allocate memory for these objects and how are they referenced later in case of a block callback.

tbag
  • 1,268
  • 2
  • 16
  • 34

1 Answers1

0

When a block is copied, it creates strong references to object variables used within the block. If you use a block within the implementation of a method:

If you access an instance variable by reference, a strong reference is made to self; If you access an instance variable by value, a strong reference is made to the variable.
I think you can read block and variables and block introduce

Feng Lin
  • 670
  • 4
  • 8
  • Yes, I have read that. I want to know how does a block do that internally. How does it allocate memory for these objects and how does it reference it? – tbag Feb 05 '15 at 02:02
  • This thing may be done in the compiler, block is a syntax unit, in compiler, it may output a static function ,in the function it retain the outside variable. – Feng Lin Feb 05 '15 at 02:13
  • For the answer to that, @tbag, see the question I've linked. It explains exactly how Blocks are implemented. – jscs Feb 05 '15 at 02:21