Re: "Capturing 'self' strongly in this block is likely to lead to a retain cycle"
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: David Duncan <email@hidden>
- Date: Tue, 10 Jul 2012 10:11:47 -0700
On Jul 10, 2012, at 12:56 AM, Jonathan Taylor wrote:
>>> In practice, NSOperationQueue probably releases the block when it's done with it
>>
>> I'm curious about your use of the word "probably" here. Can you explain?
>
> This is probably not what the OP had in mind, but I might mention that I've seen situations where autoreleases associated with NSOperationQueues and GCD queues have still been outstanding five minutes later under conditions of extremely high load. (My suspicion is that a mouse click or other user event causes these to be carried out, but I didn't test that one systematically).
GCD creates autorelease pools of "last resort" - they are basically only there to prevent what would otherwise be unavoidable leaks if they were not present. Because the threads that own these autorelease pools have an undefined lifetime, the lifetime of these autorelease pools can similarly be exceptionally long.
Basic rule of thumb thus is to create your own autorelease pool for such blocks or operations to ensure that your autoreleases are carried out in a timely manner. This is not unlike how you create your own autorelease pools when creating a new NSThread.
--
David Duncan
_______________________________________________
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