ref – https://digitalleaves.com/blog/2015/05/demystifying-retain-cycles-in-arc/
Examples of non-cycles
-
123[myArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop){[self doSomethingWithObject:obj];}];
The block retains self, but self doesn’t retain the block. If one or the other is released, no cycle is created and everything gets deallocated as it should.
-
Using dispatch_async as the example is misleading as self does not hold a strong reference to it so, there is no threat of a retain cycle.
How you get into trouble
Where you get into trouble is something like:
1 2 3 4 5 6 7 |
//In the interface: @property (strong) void(^myBlock)(id obj, NSUInteger idx, BOOL *stop); //In the implementation: [self setMyBlock:^(id obj, NSUInteger idx, BOOL *stop) { [self doSomethingWithObj:obj]; }]; |
Now, your object (self) has an explicit strong reference to the block. And the block has an implicit strong reference to self. That’s a cycle, and now neither object will be deallocated properly.