Re: ARC dealloc best pratice

2015-02-11 Thread Steve Mills
On Feb 6, 2015, at 11:34:35, Kyle Sluder wrote: > > Dealloc is too late for a lot of this stuff. I try to keep -dealloc as > pure as possible; that is, -dealloc should only be concerned with memory > management. > > Removing observers, unbinding, unregistering notifications, and timer > invalida

Re: ARC dealloc best pratice

2015-02-10 Thread Jonathan Mitchell
> On 10 Feb 2015, at 21:20, Sean McBride 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

Re: ARC dealloc best pratice

2015-02-10 Thread Sean McBride
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 situat

Re: ARC dealloc best pratice

2015-02-07 Thread Jonathan Mitchell
> On 6 Feb 2015, at 17:34, Kyle Sluder wrote: > > On Fri, Feb 6, 2015, at 08:48 AM, Jonathan Mitchell wrote: >> So I want to have a best practice template to follow in my dealloc. > > Dealloc is too late for a lot of this stuff. I try to keep -dealloc as > pure as possible; that is, -dealloc sh

Re: ARC dealloc best pratice

2015-02-06 Thread Greg Parker
> On Feb 6, 2015, at 3:27 PM, Jens Alfke wrote: > >> On Feb 6, 2015, at 2:00 PM, Greg Parker > > wrote: >> >> Swift adds "unowned" references. These references are non-retaining. They >> differ from weak references and unsafe unretained references: unowned >> referen

Re: ARC dealloc best pratice

2015-02-06 Thread Jens Alfke
> On Feb 6, 2015, at 2:00 PM, Greg Parker wrote: > > Swift adds "unowned" references. These references are non-retaining. They > differ from weak references and unsafe unretained references: unowned > references fail with a runtime error if you try to access the pointed-to > object after it h

Re: ARC dealloc best pratice

2015-02-06 Thread Greg Parker
> On Feb 6, 2015, at 1:48 PM, Jonathan Mitchell wrote: > >> On 6 Feb 2015, at 21:31, Greg Parker wrote: >> >>> 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? >> >> Some classes are i

Re: ARC dealloc best pratice

2015-02-06 Thread Jonathan Mitchell
> On 6 Feb 2015, at 21:31, Greg Parker wrote: > >> 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? > > Some classes are incompatible with (safe zeroing) weak references. For > example, a

Re: ARC dealloc best pratice

2015-02-06 Thread Jonathan Mitchell
> On 6 Feb 2015, at 17:34, Jens Alfke wrote: > > >> On Feb 6, 2015, at 6:48 AM, Jonathan Mitchell >> wrote: >> >> // remove observers >> // unregister for notifications > > I have to confess I'm still not completely certain whether these are needed > under ARC. I remember reading

Re: ARC dealloc best pratice

2015-02-06 Thread Greg Parker
> On Feb 6, 2015, at 1:18 PM, Jonathan Mitchell wrote: > >> On 6 Feb 2015, at 20:46, Jens Alfke wrote: >> >> 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? > > I presume that AppKIt (a

Re: ARC dealloc best pratice

2015-02-06 Thread Greg Parker
> On Feb 6, 2015, at 12:46 PM, Jens Alfke wrote: > >> On Feb 6, 2015, at 11:55 AM, Jonathan Mitchell >> wrote: >> >> The tableView.delegate is not a zeroing weak ref - in the lingo of ARC it is >> unsafe_unretained I believe >> self can be deallocated leaving tableView.delegate as a dangling

Re: ARC dealloc best pratice

2015-02-06 Thread Jonathan Mitchell
> On 6 Feb 2015, at 20:46, Jens Alfke wrote: > > 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? I presume that AppKIt (all of it?) is not compiled using ARC and hence doesn’t get weak refe

Re: ARC dealloc best pratice

2015-02-06 Thread David Duncan
> On Feb 6, 2015, at 12:46 PM, Jens Alfke wrote: > > >> On Feb 6, 2015, at 11:55 AM, Jonathan Mitchell >> wrote: >> >> The tableView.delegate is not a zeroing weak ref - in the lingo of ARC it is >> unsafe_unretained I believe >> self can be deallocated leaving tableView.delegate as a dangl

Re: ARC dealloc best pratice

2015-02-06 Thread Jens Alfke
> On Feb 6, 2015, at 11:55 AM, Jonathan Mitchell > wrote: > > The tableView.delegate is not a zeroing weak ref - in the lingo of ARC it is > unsafe_unretained I believe > self can be deallocated leaving tableView.delegate as a dangling pointer. This is still a weak reference, it's just unsafe

Re: ARC dealloc best pratice

2015-02-06 Thread Alex Zavatone
Here's where I am confused. I thought you were running into problems on the Mac, but I see you mention iOS 5.1 and 6.0 while you mention that you are running into problems with NSViewController. If you were running into problems on iOS, I'd expect to see UIViewController, not NSViewController.

Re: ARC dealloc best pratice

2015-02-06 Thread Jonathan Mitchell
> On 6 Feb 2015, at 17:34, Kyle Sluder wrote: > > Dealloc is too late for a lot of this stuff. I try to keep -dealloc as > pure as possible; that is, -dealloc should only be concerned with memory > management. > I agree that dealloc is far from perfect. What it does have going for it is ubiqui

Re: ARC dealloc best pratice

2015-02-06 Thread Jonathan Mitchell
> On 6 Feb 2015, at 17:34, Jens Alfke wrote: >> On Feb 6, 2015, at 6:48 AM, Jonathan Mitchell >> wrote: >> >> // remove observers >> // unregister for notifications > > I have to confess I'm still not completely certain whether these are needed > under ARC. I remember reading somet

Re: ARC dealloc best pratice

2015-02-06 Thread Jens Alfke
> On Feb 6, 2015, at 6:48 AM, Jonathan Mitchell wrote: > > // remove observers > // unregister for notifications I have to confess I'm still not completely certain whether these are needed under ARC. I remember reading something about at least one of these being handled automatica

Re: ARC dealloc best pratice

2015-02-06 Thread Kyle Sluder
On Fri, Feb 6, 2015, at 08:48 AM, Jonathan Mitchell wrote: > So I want to have a best practice template to follow in my dealloc. > At present the template looks like so. When I need a dealloc I paste this > in and fill in the blanks > > - (void) dealloc > { > // remove observers > >

ARC dealloc best pratice

2015-02-06 Thread Jonathan Mitchell
I have a mid sized (200+ nib files and associated NSView + NSWindow controllers) ARC enabled app. I have Zombie objects ON and have chased down a number of issues, most of which can be traced back to an incorrectly defined dealloc. My recent experiences have demonstrated the treacherous nature o