On 09.07.2012, at 18:03, Fritz Anderson wrote:

> You can break this by having a strong reference to self that the block can 
> manage independently.
> 
>   __block MyClass *      blockSelf = self;
>   [self.operationQueue addOperationWithBlock:^{
>       [blockSelf bar];
>       blockSelf = nil;
>   }];

Thank you Fritz for your answer.

But if I break the cycle and if I understand it correctly, 'self' won't be 
retained anymore within the block. If there are no more references to 'self' 
(except one possibly within the block), I fear 'self' will be destroyed before 
the block executes. I do require, though, that 'self' will be valid as long as 
the block is not finished.



Note: I'm using ARC in which case a retainable pointer declared with __block 
will be retained (as opposed to manual ref counting), so I should use __weak or 
__unsafe_unretained instead of __block to break the cycle (if that is what I 
have to do).

Andreas
_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to