Re: ARC dealloc best pratice
Re: ARC dealloc best pratice
- Subject: Re: ARC dealloc best pratice
- From: Jonathan Mitchell <email@hidden>
- Date: Tue, 10 Feb 2015 21:52:27 +0000
> On 10 Feb 2015, at 21:20, Sean McBride <email@hidden> wrote:
>
> On Fri, 6 Feb 2015 12:46:44 -0800, Jens Alfke said:
>
>> Come to think of it, I'm surprised that AppKit delegates are still
>> unsafe-unretained. Why haven't these been converted to safe weak
>> references yet?
>
> The 'why' has been answered, but worse it's not even clear sometimes what a delegate's situation is. Take NSTableView.h in the 10.10 SDK:
>
> -------------
> /* Get and set the delegate. The delegate can implement methods in the protocol NSTableViewDelegate. All delegate methods are optional. The delegate is a weak reference (non retained) in non garbage collected applications. Under garbage collected apps, it is a strong reference. The default value is 'nil'.
> */
> - (void)setDelegate:(id <NSTableViewDelegate>)delegate;
> - (id <NSTableViewDelegate>)delegate;
> -------------
>
> So based on Greg saying "We prefer to reserve the term 'weak' for safe zeroing weak." I guess for NSTableView there's no need to nil the delegate. OTOH, my experience converting my GC app to ARC says the exact opposite.
>
I think that what Greg means is that when used in the context of ARC weak is a synonym for zeroing weak.
Weak is also used (as you have shown) in the AppKit documentation, and likely dates back to the introduction of GC which also used weak and strong modifiers.
AppKit is not compiled using ARC so any ref to a weak reference cannot imply a zeroing weak reference.
> Without clearing the delegate to nil in say windowWillClose, I get sporadic crashes.
I agree that zeroing out these unretained delegates remains a necessity.
Jonathan
_______________________________________________
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