Re: Release a NSWindowController after the window is closed
Re: Release a NSWindowController after the window is closed
- Subject: Re: Release a NSWindowController after the window is closed
- From: Quincey Morris <email@hidden>
- Date: Sat, 18 Jun 2011 00:03:29 -0700
On Jun 15, 2011, at 11:40, Brian Norh wrote:
> Is there a better way to do this? I have searched the documentation
> and have not found anything specific on which practices to use. It
> sounds like something very basic which it should cover so maybe I'm
> just searching with the wrong terms.
I'm not sure why you're uncomfortable with your solution, at least uncomfortable enough to be checking for a "better" way. However, I'll offer the following (subjective) comments:
-- There's perhaps a very slight code smell associated with an object that retains itself. But in a case like this where it's very clear what's going on I don't think it's anything to worry about.
-- The code as written isn't compatible with GC or ARC. (In one, the 'retain' won't keep the window controller alive, and in the other it's illegal.) An alternate is to have the application delegate maintain an array of window controllers, a solution that's compatible with all memory management models. It's a trivial amount of extra code.
-- This usage case, multiple independent windows, is a little bit unusual in Cocoa applications. Usually it's a single window controller for the main window, or multiple window controllers associated with NSDocument instances. Note that a NSDocument instance maintains an array of window controllers for you, and the NSDocumentController singleton maintains an array of documents.
I mention the NSDocument case because there is some useful functionality there (in terms of the window title, the title bar icon, the Window menu, disambiguation of clashing document names, etc) that it's tedious to re-create, if it's appropriate to your application. It wouldn't necessarily be a silly idea to use the NSDocument model anyway, even if there are no actual document files, if there's any convergence between the NSDocument model and your application design.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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