Re: Cleaning up weak references ( was Re: Odd Crash when adding table columns manually )
Re: Cleaning up weak references ( was Re: Odd Crash when adding table columns manually )
- Subject: Re: Cleaning up weak references ( was Re: Odd Crash when adding table columns manually )
- From: Corbin Dunn <email@hidden>
- Date: Thu, 20 Jan 2011 18:39:52 -0800
On Jan 20, 2011, at 1:33 PM, Abdul Sowayan wrote:
> Hi Corbin,
>
>
>> I wrote that sample, and gave the WWDC talk based on it a few years ago. I
>> also "own" NSTableView.
>>
>> Yes, please do file a bug. The sample should set the delegate/datasource to
>> nil, as it is good practice to do so, and we can update the sample.
>
> Thanks for the clarification, it is very helpful. So the right thing to do
> with delegates/datasources is to set them to nil.
>
> What about target/action on something like a button?
>
> Would you say that for every control in a nib, one has to set the
> delegate/datasource/action to nil? While this might seem like a silly
> question, most books/examples I read don't do this so I wanted to be clear
> on what the right thing to do is.
No, I wouldn't say every control -- I would say any control that has a delegate method which responds to drawing commands. Things like NSTableView, NSOutlineView, NSBrowser, NSWindow. I mainly know from experience of debugging and looking at crash reports.
Now for something like a button, it obviously won't run into this type of latent drawing issue, since they don't message the delegate every time they draw. However, if you temporarily allocated an object and set it as the target/action of a button, and then free that object while the button is still visible, then yes, that's a case where you want to reset it to nil.
Most these type of crashing issues can easily be resolved by using instruments + zombies -- you quickly realize your object was deallocated, but the view object had a reference to it.
corbin
_______________________________________________
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