Re: premature dealloc of the datasource of a NSTableView crashes my application
Re: premature dealloc of the datasource of a NSTableView crashes my application
- Subject: Re: premature dealloc of the datasource of a NSTableView crashes my application
- From: "Michael Ash" <email@hidden>
- Date: Sun, 5 Oct 2008 16:19:35 -0400
On Sun, Oct 5, 2008 at 1:31 PM, Brian Stern <email@hidden> wrote:
>
> On Oct 4, 2008, at 11:36 PM, Michael Ash wrote:
>>
>> Absolutely not. Write your code to work with any order. In this case,
>> what you should do is write your data source to nil out the table's
>> reference to it when it goes away:
>>
>> - (void)dealloc {
>> [tableView setDataSource:nil];
>> [super dealloc];
>> }
>
> What prevents the tableview from being dealloced before the datasource? In
> that case the datasource is messaging a stale pointer.
>
> I think that something higher up in the ownership graph needs to manage
> this, like the window controller.
Good point! The window controller could handle it, although that can
be annoying as it's something of a closer coupling than there maybe
should be. I'd say that in this situation, the data source ought to
retain the table view as well, which allows you to safely nil out the
table view's reference to the data source, with a -dealloc method like
this:
- (void)dealloc {
[tableView setDataSource:nil];
[tableView release];
[super dealloc];
}
(And of course you would need a setter which retains it, to balance
the release.)
Mike
_______________________________________________
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