Re: NSTableView is messaging zombie delegate
Re: NSTableView is messaging zombie delegate
- Subject: Re: NSTableView is messaging zombie delegate
- From: Jonathan Mitchell <email@hidden>
- Date: Fri, 06 May 2016 21:27:05 +0100
> On 6 May 2016, at 21:03, Matthew LeRoy <email@hidden> wrote:
>
> Hello,
>
> I'm having an issue where an NSTableView appears to be messaging its delegate after the delegate has been deallocated, causing an EXC_BAD_ACCESS crash. It doesn't always happen, but it happens regularly. My understanding is that NSTableView's delegate is a zeroing weak reference, and so I'm stumped as to how/why it is sending a message to the delegate after the delegate has been deallocated.
Its a weak reference, not a zeroing weak reference.
So when your delegate disappears the NSTableView delegate still points to it unless you manually intervene.
You only get the zeroing weak behaviour when you build with arc.
I don’t know if AppKit is built with arc enabled or not but the NSTableView delegate is declared as a getter/setter pair rather than a weak property.
This catches us out because we are used to seeing the arc zeroing behaviour in our own arc enabled code.
We forget that some of the objects we interact with don’t act quite the same.
WebView delegates for instance behave in the same way.
I generally set my table and web view delegates to nil in the NSViewController dealloc - this precaution seems to pay off in terms of increased stability when view hierarchies get torn down.
J
_______________________________________________
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