Re: ARC dealloc best pratice
Re: ARC dealloc best pratice
- Subject: Re: ARC dealloc best pratice
- From: Alex Zavatone <email@hidden>
- Date: Fri, 06 Feb 2015 15:07:47 -0500
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.
Do you mean UIViewController and iOS or are these Mac OS issues?
Thanks,
Alex
Sent from my iPad. Please pardon typos.
On Feb 6, 2015, at 2:55 PM, Jonathan Mitchell <email@hidden> wrote:
>
>> On 6 Feb 2015, at 17:34, Jens Alfke <email@hidden> wrote:
>>> On Feb 6, 2015, at 6:48 AM, Jonathan Mitchell <email@hidden> 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 (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
_______________________________________________
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