Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden

References: 
 >Re: Completely remove a window (from NSApp)? (From: Matt Neuburg <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.