- Can I be sure that myObj is still alive and actual here after the long processing (*)?
Yes. Normally, free variables in a block are retained by the block when it is copied. However, this is a __block
variable. In ARC, __block
variables are also retained by the block (however, that is not the case in MRC).
- Can I be sure that myObj is still alive and actual here after the long processing (**) finishes?
This question isn't related to blocks capturing variables at all. Here, myObj
is a parameter, i.e. a local variable, not captured from the surrounding scope. So the question really is, does the argument point to a valid object when the block is called? Since myMethod()
simply synchronously calls its block
argument with the myObj
argument that it gets, under ARC, nothing should go wrong assuming that the arguments were valid when myMethod
was called (i.e. in the outer block). This is true since we agreed that myObj
was valid there from (1) above.