• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: "Capturing 'self' strongly in this block is likely to lead to a retain cycle"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "Capturing 'self' strongly in this block is likely to lead to a retain cycle"


  • Subject: Re: "Capturing 'self' strongly in this block is likely to lead to a retain cycle"
  • From: Andreas Grosam <email@hidden>
  • Date: Tue, 10 Jul 2012 07:39:02 +0200

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@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: "Capturing 'self' strongly in this block is likely to lead to a retain cycle"
      • From: email@hidden
References: 
 > "Capturing 'self' strongly in this block is likely to lead to a retain cycle" (From: Andreas Grosam <email@hidden>)
 >Re: "Capturing 'self' strongly in this block is likely to lead to a retain cycle" (From: Fritz Anderson <email@hidden>)

  • Prev by Date: Field Editor told to replace range {0, NSUIntegerMax} : Range Exception
  • Next by Date: Re: turning app into background app
  • Previous by thread: Re: "Capturing 'self' strongly in this block is likely to lead to a retain cycle"
  • Next by thread: Re: "Capturing 'self' strongly in this block is likely to lead to a retain cycle"
  • Index(es):
    • Date
    • Thread