• 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: ARC dealloc best pratice
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >ARC dealloc best pratice (From: Jonathan Mitchell <email@hidden>)
 >Re: ARC dealloc best pratice (From: Jens Alfke <email@hidden>)
 >Re: ARC dealloc best pratice (From: Jonathan Mitchell <email@hidden>)
 >Re: ARC dealloc best pratice (From: Jens Alfke <email@hidden>)
 >Re: ARC dealloc best pratice (From: Sean McBride <email@hidden>)

  • Prev by Date: Re: ARC dealloc best pratice
  • Next by Date: Question for StackOverflow or other about not sharing cookie jar per webview
  • Previous by thread: Re: ARC dealloc best pratice
  • Next by thread: Re: ARC dealloc best pratice
  • Index(es):
    • Date
    • Thread