dealloc, release, NSWindowController
dealloc, release, NSWindowController
- Subject: dealloc, release, NSWindowController
- From: "baron.s" <email@hidden>
- Date: Thu, 29 Jan 2004 13:14:58 +0100
I dont't understand how i should implement my dealloc method.
in my project i have several windows which i want to release for memory
reason.
The dealloc method in the main app controller (MainMenu) is never
called (took sample in Cocoa Programming )
the dealloc method in the NSWindowController is called only if i use
the delegate method windowWillClose and use:
[self autorelease];
then dealloc is called but if i want to reopen the window which have
been released the app crach.
I understand that the calling method in the main app controller
(showPreferenceController) is called but the alloc init line is not
executed so the app crach.
why ??
preferenceController shouldn't be equal to Nil after autorelease and
dealloc??
here is a sample code.
(i have searched in the list archive but find nothing explaining this,
and i know that it's better for rapidity to not release a window if she
is possibly called again after)
//
// AppController.m
// TestDealloc
//
#import "AppController.h"
#import "PreferenceController.h"
@implementation AppController
-(IBAction)showPreferenceController:(id)sender;
{
if(!preferenceController)
{
preferenceController=[[PreferenceController alloc]init];
}
[preferenceController showWindow:self];
}
-(void)dealloc
{
NSLog(@"dealloc");
///===== never called
[super dealloc];
}
@end
//
// PreferenceController.m
// TestDealloc
//
#import "PreferenceController.h"
@implementation PreferenceController
-(id)init
{
self=[super initWithWindowNibName:@"Preference"];
return self;
}
-(IBAction)btClose:(id)sender; //close the window
{
[self close];
}
-(void)windowWillClose:(NSNotification *)aNotification
{
[self autorelease];
}
-(void)dealloc
{
NSLog(@"dealloc 2");
[super dealloc];
}
@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.