> On 6 Feb 2015, at 17:34, Jens Alfke <j...@mooseyard.com> wrote:
>> On Feb 6, 2015, at 6:48 AM, Jonathan Mitchell <jonat...@mugginsoft.com> 
>> 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 automatically, but I just skimmed through some docs now and couldn't 
> find anything. I tend to put these in my classes but always wonder whether I 
> strictly need to.
I would say it is necessary. Warnings result otherwise and unremoved observers 
do seem to lead to instability.

> 
>>      // set any non-weak delegates to nil (NSTableView et al)
> 
> I think you meant "set any _weak_ delegates to nil", i.e. clear the delegate 
> property of any object of whom I'm the delegate. Non-weak doesn't make sense, 
> because if a delegate has a strong reference to self, then self can't 
> possibly be in its dealloc method.
Sorry. I wasn’t clear enough probably.
Most of my issues centre around NSViewController.
Say I have an outlet to an NSTableView and the tableView.delegate = self.
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.

> 
> Note that this is only necessary if (a) the other object can outlive self, 
> and (b) the other object could still send the delegate messages in the future.
> 
The problem is that there is, I believe, no way to accurately determine whether 
a or b is true in any particular instance!
Recently I have resolved issues where both NSTableView and WebView were sending 
delegate messages and responder chain actions in situations that I hadn’t 
expected.
A stone dead app is the result.

Jonathan
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to