Re: One Shot Windows: WARNING
Re: One Shot Windows: WARNING
- Subject: Re: One Shot Windows: WARNING
- From: Michael Ash <email@hidden>
- Date: Tue, 10 Feb 2009 11:12:17 -0500
On Tue, Feb 10, 2009 at 1:02 AM, Matt Neuburg <email@hidden> wrote:
> Actually, having looked at your example, I reproduced the crash from the
> bottom up by starting with the Document Architecture template.
>
> I created a window controller class, made it the Document nib's owner,
> overrode makeWindowControllers, put a table view in the window, made the
> nib's owner the table view's data source, and put code in the window
> controller to populate the table. Sure enough, it worked fine, but when I
> unchecked One Shot, it crashed if I closed the window with command-W.
>
> The crash doesn't happen if there is just an NSDocument; it has something to
> do with the intermediate NSWindowController. m.
The order of object destruction in a graph such as this is not well
defined. You have no guarantees as to who will go first. As such,
whenever you have a weak reference to an object, such as the
dataSource outlet in a table view, you must explicitly break that weak
reference in your -dealloc method. If you don't, the possibility
exists that the table view will outlive your object *and* that it will
try to message it after it has gone. This is likely to be the root of
your problem here.
The solution? Explicitly nil the table view's dataSource in your dealloc method:
- (void)dealloc {
[tableView setDataSource:nil];
[super dealloc];
}
And do this for any other weak references as well, such as delegates.
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