0
votes

I am working on some Cocoa exercise for beginners. Asking this because applications like iTunes do not really terminate when their red buttons are clicked. I have a NSPanel object with the "release when close" option checked. An IBOutlet variable is set up to point to the NSPanel object using IB. When the NSPanel object is closed by the red button, the pointer variable is assigned "nil" by a delegate method. When the pointer is "nil", the user could load the NSPanel's nib file again (using loadNibName indirectly) and redisplay the panel.

My question is : if the NSPanel object is not fully removed when closed then would memory be wasted when the NSPanel's nib file is being loaded the second time ? (since the panel is an "About Panel" and there should only be one such window on display. And its nib file is being loaded twice...)

1
If "release when closed" is checked, it will be released when it is closed. Otherwise it won't.ughoavgfhw
The method : [NSBundle loadNibNamed: ...] is used because it is some Cocoa exercise for beginners. Hope that some experts or people who have more experience than me can share some thoughts on this.Stanley
@ughoavgfhw are you saying that the nib file can be loaded any number of times without any undesirable effect as long as "release when closed" is checked?Stanley
As long as there is no NSWindowController attached to it, yes. See developer.apple.com/library/mac/documentation/cocoa/reference/…ughoavgfhw
@ughoavgfhw, thanks for your comment and hyper link, they are very useful ...Stanley

1 Answers

0
votes

As pointed out by ughoavgfhw, the "release when close" option when chosen will cause the panel to be removed from memory. So we do not really have to worry about loading the nib file multiple times. But I suspect that letting the panel stay in memory when closed would improve respond time since the nib file will not need to be reloaded. However, it may cause some extra memory used. In practice, response time on my Mac mini 2.4 GHz Core 2 Duo in this case is not an issue at all. The display time of the about panel is instantaneous even when the nib file has to be loaded every time. It may be an issue on iPhone though...