Can't release a NSWindowController when a window close
Can't release a NSWindowController when a window close
- Subject: Can't release a NSWindowController when a window close
- From: Luca Caviglione <email@hidden>
- Date: Sun, 21 Jan 2007 20:37:50 +0100
Hi List,
I am developing a little NSStatusItem app. The app has a menu and it is possible
to launch different "widgets". Each "widget" has a custom NSWindow, NSView and
NSWindowController. In addition, there are NSTimers in my custom views for
animation purposes and in the custom NSWindowController for checking some
system parameters (e.g., when the user is idle).
The user can turn on/ turn off "widgets" in the menu. For doing so, in the menu
controller there are methods like (each method spawns a separate controller):
======Method that initiates the custom WindowController===
//Toggle Larry Pops Up! Widget
- (void) toggleLarryPopsUp:(id)sender
{
if (!lslPopsController)
{
lslPopsController = [[[lslMenuLarryPopsUpController alloc] init] autorelease];
if(!isLarryPopsUpOn)
{
//Show window
[lslPopsController showWindow:self];
isLarryPopsUpOn = TRUE;
}
}
else
{
//Hide Window
[lslPopsController close];
isLarryPopsUpOn = FALSE;
}
}
lslPopsController is declared in the .h of the menu controller as:
//Pointer to lslMenuLarryPopsUpController
lslMenuLarryPopsUpController *lslPopsController;
However, custom controllers are never deallocated. Digging the documentation and
the archives, I tried also the following. In each custom NSWindowController I
added:
- (void) windowWillClose:(NSNotification *) notification
{
[self autorelease];
}
Also, I tried to modify the code as suggested in
http://www.cocoabuilder.com/archive/message/cocoa/2004/9/1/116358
but it doesn't work. The controller is never released. The proper dealloc method
is never called and hence I have also timers continuing to fire (but every time
a timer is used, the proper invalidate-release are implemented in the dealloc)
and memory leaks. I tried also to release the controller after the
[lslPopsController close], but the app crashes. Also I tried also to avoid
autorelease or using a local autorelease pool. I can't find the error and I
tried in different ways.
Simply, I would like to launch a custom NSWindowController and completely
dismiss it when the user close it (not by clicking on the window, but sending
to the controller a close, like in the previous snippet).
Any clues on how to solve this?
Thank you in advance!
Luca
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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