• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Completely remove a window (from NSApp)?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

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

  • Prev by Date: Re: ffmpeg and NSTask
  • Next by Date: Re: changing cell controls in an NSOutlineView
  • Previous by thread: Re: Completely remove a window (from NSApp)?
  • Next by thread: Re: Completely remove a window (from NSApp)?
  • Index(es):
    • Date
    • Thread