On Oct 16, 2010, at 9:41 AM, Hrishikesh Murukkathampoondi wrote:

> I am trying to learn how to open a second window in an Application (Mac OS X, 
> not iOS). I have created a separate Nib file for loading the second window. I 
> have a couple of questions
> 
> 
> Q1. The "Resource Programming Guide" says the following
> 
> "The NSWindowController class also provides automatic support for loading nib 
> files. If you create custom window controllers programmatically, you have the 
> option of initializing them with an NSWindow object or with the name of a nib 
> file. If you choose the latter option, the NSWindowController class 
> automatically loads the specified nib file the first time a client tries to 
> access the window. After that, the window controller keeps the window around 
> in memory; it does not reload it from the nib file, even if the window’s 
> “Release when closed” attribute is set in Interface Builder."
> 
> I have created a Nib file (MySecondWindow.xib), I also created a 
> NSWindowController class (MyWinController). In IB the "File's Owner" of the 
> new Nib file is set to MyWinController.
> 
> 
> I guess I can show the second window by doing something like this in some 
> method in MyDocument.m -
> 
> mySecondWin = [[MyWinController alloc] 
> initWithWindowNibName:@"MySecondWindow"];

Juts to be clear, starting with this yes, but that method alone isn't 
sufficient to actually show the window.

> How do I release the memory once the window is closed? The description above 
> says that the window is kept in memory even if closed.

http://lmgtfy.com/?q=nswindowcontroller+release+when+window+closed

> Q2. In the same "Resource Programming Guide" a later section talks about 
> loading Nib files programmatically using NSBundle and NSNib classes to load a 
> new Nib. Using NSNib allows you to keep the NSNib object around to load 
> additional "copies" of the same type of window (with other controllers).
> 
> Releasing the NSNib object and any mySecondWin controller objects will 
> release all memory associated with MySecondWindow. Correct?

Usually, but not necessarily, as there could be a retain cycle with the File's 
Owner. As long as you do not bind to File's Owner, or have retained outlets to 
same, the objects created from the nib will almost always get released.

HTH,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to