NSWindowController and -[NSWindow isReleasedWhenClosed]

I noticed that the Resource Programming Guide has been updated for ARC, which prompted me to investigate something that has puzzled me for a long time: how does NSWindowController interact with NSWindow’s “convenience” method -isReleasedWhenClosed?
It turns out that NSWindowController actually calls -setReleasedWhenClosed:NO on its window as part of -setWindow:. It doesn’t matter if NSWindowController loaded the window from nib, or if it was initialized with -initWithWindow: directly.

This makes memory management of NSWindowController-owned windows saner. And nowadays, with our multi-core multi-GHz machines packed with oodles of RAM, it’s worth spending the extra bytes to create an NSWindowController to manage your windows rather than rely on the arcane -isReleaedWhenClosed method (and its equally-outmoded companion, the “visible at launch” flag in Interface Builder).

I’d really prefer if the Window nib templates assumed File’s Owner was an NSWindowController and unchecked the “Release when closed” checkbox by default. NSWindowController’s cleanup behavior means you can leave the “Release when Closed” checkbox checked but still reopen a closed window, which is misleading and probably the source of my confusion in the first place. I’ve filed this request as rdar://10349276 (also viewable on OpenRadar).

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>