Modernize Window NIBs: use NSWindowController, uncheck "Release when Closed"

Number:rdar://10349276 Date Originated:10/26/2011
Status:Open Resolved:
Product:Developer Tools Product Version:4.2/4D199
Classification:UI/Usability Reproducible:Always

Interface Builder's defaults for NSWindows don't reflect modern best practices. New NSWindows created from the object library or from the "Window" template have the "Release when Closed" attribute set (-setReleasedWhenClosed:YES), and the class of File's Owner for the Window template is assumed to be an NSObject.

The "Release when Closed" attribute should not be set by default. If one is using an NSWindowController to manage the window, then NSWindowController will disable the Release when Closed attribute and correctly manage the window's lifecycle itself. This leads to the misleading scenario of the Object Inspector indicating that the window will be released when closed, but the window actually not being released and therefore functioning correctly if ordered back onscreen after being sent a -close message.

Even if the window is not being managed by an NSWindowController, ARC prohibits unbalanced -retain and -release. To deal with the extra retain given to top-level NIB objects, the Resource Programming Guide encourages creating outlets from File's Owner to top-level objects, casting them to CFType, and calling CFRelease. To promote consistency, windows should not be given the "Release when Closed" flag by default. The option can remain there for those who understand it to turn on, but the true solution should be to encourage using NSWindowController or NSViewController to own and load the NIB file.

This best practice can be further encouraged by making NSWindowController the default class of File's Owner for the Window NIB template, and hooking up the window outlet to the window. It would also save me much repeated embarrassment and frustration since I constantly forget to hook up the window outlet. I'm sure I'm not alone.

Steps to Reproduce:

1. Choose File > New > New File.
2. Choose the Mac OS X > User Interface > Window template.
3. Give a name to the NIB file and choose Save.
4. Select the window object and note the state of its "Release when closed" checkbox on the Attributes Inspector.
5. Select the File's Owner proxy and note its class on the Identity Inspector.

Expected Results:

The window's "Release when closed" checkbox is unchecked, and the class of File's Owner is set to NSWindowController.

Actual Results:

The window's "Release when closed" checkbox is checked, and the class of File's Owner is set to NSObject.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!