1, 2) Blocks retain the object-pointers in it (any blocks, dispatch_async blocks are nothing special). This usually isn't a problem, but can lead to retain-cycles, because the block can be associated with an owner object and that owner object (often self
) might be retained by the block. In that case you should use a weak variable and then reassign it to a strong capture:
__weak MyClass *weakSelf = self;
self.block = ^{
MyClass *strongSelf = weakSelf;
...
[strongSelf ...];
[strongSelf.property ...];
[strongSelf->iVar ...];
}
Note: If you access an iVar directly, the compiler will transform that into self->iVar and thus retains self!
3) Blocks only retain the pointers, they don't copy them.
4) Variables created inside a block belong to that block and will be released when that block goes out of scope.
__block
now creating a strong reference, have changed.