Re: __block __weak - am I doing this right?
Re: __block __weak - am I doing this right?
- Subject: Re: __block __weak - am I doing this right?
- From: Ken Thomases <email@hidden>
- Date: Thu, 16 Feb 2012 17:57:54 -0600
On Feb 16, 2012, at 2:05 PM, Greg Parker wrote:
> On Feb 16, 2012, at 8:22 AM, Matt Neuburg <email@hidden> wrote:
>> On Wed, 15 Feb 2012 16:20:50 -0800, Greg Parker <email@hidden> said:
>>>
>>> Are you using GC or ARC? I think this is safe with GC but not safe with ARC, but I'm not an expert in the NSNotificationCenter machinery.
>>
>> ARC, but I don't see how it might be unsafe. I sure *hope* it isn't, because that's what the __weak is for. You need that because if your observer doesn't vanish in good order, neither will +self+, because the observer retains +self+, not just while registered with the notification center but for as long as it lives (by way of the block, I presume). *That* is something I *do* understand, having spent many hours watching the retain counts at work.
>
> The question is, who retains the observer? The __block __weak variable does not, because it's weak. NSNotificationCenter does not, as I understand it.
I was worried about that, too, but the -[NSNotificationCenter addObserverForName:object:queue:usingBlock:] docs say:
"In a reference counted environment, the system retains the returned observer object until it is removed, so there is no need to retain it yourself."
ARC does still count as a reference counted environment, I assume.
Regards,
Ken
_______________________________________________
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