Re: Completely remove a window (from NSApp)?
Re: Completely remove a window (from NSApp)?
- Subject: Re: Completely remove a window (from NSApp)?
- From: Jerry Krinock <email@hidden>
- Date: Wed, 27 Dec 2006 17:34:55 -0800
- Thread-topic: Completely remove a window (from NSApp)?
The short answer is:
THANKS Matt and Patrick, -setReleasedWhenClosed does what I was looking for!
Longer answer...
on 06/12/27 15:41, Matt Neuburg at email@hidden wrote:
> If you're concerned about the Window list shown in the Window menu,
No, that was not what I was concerned about
>
> If you are concerned about the memory used by a window, use
> setReleasedWhenClosed, or employ the nib architecture (esp. with
> NSWindowController, though that is not absolutely necessary).
In particular, I wanted it out of -[NSApp windows] because I use -[NSApp
windows] in the -documents implementation of my slightly hacked
NSDocumentController subclass. If, after closing a window, it is still in
-[NSApp windows], it still gets returned by my [SSDocumentController
documents], which the Cocoa framework invokes as it does its "quit" thing.
So, if a user clicked "Don't Save", the document window would momentarily
disappear but then reappear. Secondarily, I thought it would be polite to
release the memory for the window when I closed and released the associated
document.
But indeed, if I -setReleasedWhenClosed:YES, and then -close a window, it is
instantly removed from -[NSApp windows]. So, apparently
-setReleasedWhenClosed is the magic behind NSApp removing a document; a more
accurate name would be -removeFromNSAppWhenClosed. But I'm fine with magic
as long as it works :) This works in an NSWindowController category or
subclass:
- (void)removeWindow {
// Use this to remove and release a window from the app
// This will remove it from -[NSApp windows]
[[self window] setReleasedWhenClosed:YES] ;
[self close] ;
}
Thanks again,
Jerry
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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