Re: Getting rid of an NSWindowController
Re: Getting rid of an NSWindowController
- Subject: Re: Getting rid of an NSWindowController
- From: Matt Neuburg <email@hidden>
- Date: Mon, 4 Feb 2002 11:33:32 -0800
On Sun, 03 Feb 2002 17:56:52 -0800, Matt Judy <email@hidden> said:
>
I've got a multi-window (non-document-based) app that uses an
>
NSWindowController to create, setup, and manage the windows. My app is
>
leaking bigtime, though, because nothing in the window is released when
>
the window is closed. I thought this might have happened automatically,
>
but not so.
>
>
So, what and when is the correct way to get rid of an
>
NSWindowController, its associated window and contents when the window
>
closes?
The correct way to "get rid of" something is to release it.
I'm not sure what you mean by "nothing in the window" - that is, I'm having
a little trouble with the notion of a thing being "in" a window.
Perhaps the following elementary considerations, culled from the
documentation, will suggest something to you. A window will be released
when it is closed if you have set its isReleasedOnClose to YES (you can do
this in IB with a checkbox). Furthermore, if you have set up your nib file
correctly, with the NSWindowController as its owner, then it will release
all top-level objects in the nib file when you release the
NSWindowController; if not, then releasing them is up to you.
Accordingly, the way I handle this entire situation in my app is as
follows. For each extra window, I have a nib file and an NSWindowController
that owns it. When the user summons the window, in my main controller I
instantiate the NSWindowController, which proceeds to load and show the
window. The window is set to release on close. When the user closes the
window, I detect this fact by means of the WindowWillClose notification
back in my main controller, and autorelease the NSWindowController. All is
now as it was before the user summoned the window. m.
--
matt neuburg, phd = email@hidden,
http://www.tidbits.com/matt
pantes gar anthropoi tou eidenai oregontai phusei
Subscribe to TidBITS! It's free and smart.
http://www.tidbits.com/