Re: Window controllers and memory leaks
Re: Window controllers and memory leaks
- Subject: Re: Window controllers and memory leaks
- From: Jerry Krinock <email@hidden>
- Date: Sat, 14 Sep 2013 10:28:34 -0700
On 2013 Sep 13, at 12:11, Kyle Sluder <email@hidden> wrote:
> Add a property to your app delegate that retains the window controller.
> Have your window controller listen for NSWindowDidCloseNotification from
> its window, and send a message to the app delegate. In response to this
> message, the app delegate should release the window controller (probably
> by assigning its property to nil).
That is good, and I've done it that way. But my app delegates get so damned long, so last year I put that boilerplate delegation and notification observing code into a subclass of NSWindowController. In cases where you can live with that (no multiple inheritance), and want to have only one window of a given class (a Preferences window, for example), it "works for me". To add a new "self-releasing" window to your project, 3 steps…
• Make the new FooWindowController a subclass of SSYTempWindowController.
• In FooWindowController, override +nibName.
• To display the window, +[FooWindowController showWindow].
That's all. It loads the nib, shows the window, and all goes away when the user closes it.
SSYTempWindowController.m is 62 lines including whitespace…
https://github.com/jerrykrinock/ClassesObjC/blob/master/SSYTempWindowController.m
_______________________________________________
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