Cleaning up weak references ( was Re: Odd Crash when adding table columns manually )
Cleaning up weak references ( was Re: Odd Crash when adding table columns manually )
- Subject: Cleaning up weak references ( was Re: Odd Crash when adding table columns manually )
- From: Eric Gorr <email@hidden>
- Date: Thu, 20 Jan 2011 10:22:41 -0500
On Jan 19, 2011, at 8:24 PM, Eric Gorr wrote:
> On Jan 19, 2011, at 8:19 PM, Graham Cox wrote:
>
>> On 20/01/2011, at 12:14 PM, Eric Gorr wrote:
>>
>>> The table is also owned by the the scrolling view and therefore the window and would not be deallocated here...it will stick around long after the controller is deallocated.
>>
>> You're right, but since the table owns its columns, it is still the table's job to manage them, not yours.
>
> Agreed. I never liked the solution, which is one of the reasons why I posted the message to begin with.
>
>> Glad you got it solved anyway, but it's nice to know that the best solution turned out to be the correct, documented and recommended one after all!
>
> Indeed. Learned stuff too...I had not fully understood the rules regarding weak references before.
>
> Hopefully this thread has helped others as well.
I was wondering why this was such a surprise to me, so I went hunting through sample code, books, etc.
I cannot seem to find any sample code, either in books (even Cocoa Programming for Mac OS X (3rd Edition)) or in Apple's own sample code where they follow these rules. I think that is why it has surprised me. I sure there must be some out there that do follow these rules, but the examples seem to be rare at the moment.
For a specific example, check out the AnimatedTableView sample code from Apple. The ATColorTableController class is a datasource for the table, but it's dealloc looks like:
- (void)dealloc
{
[_colorList release];
[_colorNames release];
[_window release];
[super dealloc];
}
Based on my current understanding, the dealloc should be setting it's datasource and delegate to nil. Correct? If so, I will file a bug.
Or, what is the reason why the code as written is correct?
_______________________________________________
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