Will this lead to any sort of retain cycle? Is it safe to use?
__block void (^myBlock)(int) = [^void (int i)
{
if (i == 0)
return;
NSLog(@\"
If you are using ARC, you have a retain cycle, because __block
object variables are retained by the block. So the block retains itself. You can avoid it by declaring myBlock
as both __block
and __weak
.
If you are using MRC, __block
object variables are not retained, and you should have no problem. Just remember to release myBlock
at the end.