I have a question on "best style" regarding Cocoa architecture.
I have a controller that manages a small dialog window. When the controller is initialized the dialog is shown.
There's also a showDialog method. If the dialog is minimized or otherwise obscured the method throws the dialog to the front. If the nib hasn't been loaded it gets loaded. The code is like this:
This works only if I in IB don't check the "Release when closed" check box under the window's attributes. If I do check it my outlet pointers (fx originalNumberTextField) are stale and I end up accessing bad memory, and then the program crashes.
I gather in some case it is fine not to release the window when closed, but in some cases it is a good idea to do (memory-wise).
So my questions are this:
1. If I choose to release the window when closing, how should I go about the situation since my pointers are stale? Do I need to listen for some notification for the release of the window and then set my outlets to nil?
2. Is there some Cocoa idiom I am missing on how to manage this?
I have a controller that manages a small dialog window. When the controller is initialized the dialog is shown.
There's also a showDialog method. If the dialog is minimized or otherwise obscured the method throws the dialog to the front. If the nib hasn't been loaded it gets loaded. The code is like this:
Code:
-(void) showDialog {
if (!originalNumberTextField) {
if (![NSBundle loadNibNamed:@"ConvertNumberToBase"
owner:self])
{
NSLog(@"Error loading Nib for ConvertToBase dialog!");
return;
}
}
[[originalNumberTextField window] makeKeyAndOrderFront:self];
}
This works only if I in IB don't check the "Release when closed" check box under the window's attributes. If I do check it my outlet pointers (fx originalNumberTextField) are stale and I end up accessing bad memory, and then the program crashes.
I gather in some case it is fine not to release the window when closed, but in some cases it is a good idea to do (memory-wise).
So my questions are this:
1. If I choose to release the window when closing, how should I go about the situation since my pointers are stale? Do I need to listen for some notification for the release of the window and then set my outlets to nil?
2. Is there some Cocoa idiom I am missing on how to manage this?