gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: When should an NSDocument stop being an NSWindow's delegate?


From: Fred Kiefer
Subject: Re: When should an NSDocument stop being an NSWindow's delegate?
Date: Sun, 25 Oct 2009 21:36:47 +0100
User-agent: Thunderbird 2.0.0.23 (X11/20090817)

David Chisnall schrieb:
> I am currently experiencing some crashing due to an NSWindow's
> _performClose method being called after the document (which was its
> delegate) is freed.  It looks like there is something wrong in the
> NSDocument infrastructure, because the _window ivar is never retained by
> NSDocument, but it is released on -dealloc (possibly this should be a
> -performClose or similar, because NSWindow is meant to retain itself and
> release itself when it is closed?).
> 
> This usually doesn't make much difference, because the window controller
> takes ownership, and then sets the _window ivar in the document to nil,
> and so the release message is sent to nil instead of the window.

What goes on here is really some unusual coding and it took me some time
to accept it. If you have a better way of doing this ownership transfer
that is required in the common case. I am willing to change this.
But what ever goes on here is totally unrelated to the issue you are
having. Just forget about this _window ivar.

> The problem comes if you follow the common pattern of setting the
> document (the file's owner) as the window's delegate in the nib.  In
> order for this not to crash when the window sends a respondsToSelector:
> message to the delegate while closing, the document must remove itself
> as the delegate before it exists.  This would be easy, except that the
> window controller has stolen the window and the window controller itself
> has removed itself from the array of window controllers by the time
> -dealloc is called, so there is no way for an NSDocument subclass to get
> the window in -dealloc and do this removal...

Your problem is that you have the document as the delegate of the
window, but don't have a way to remove this relationship, when the
document gets deallocated. I think the best you can do in that case is
to remove the delegate of the window in _removeWindowController:. But at
that time the controller no longer has a reference for that window. We
may need to swap a few lines of code here.
The GNUstep code of NSWindowController has special handling for the case
where the controller is the delegate of the window. Perhaps this
constellation would fit your needs better? Or we could add similar
special code for the document being the delegate at the same place?




reply via email to

[Prev in Thread] Current Thread [Next in Thread]