NSTimer - crash when closing window
NSTimer - crash when closing window
- Subject: NSTimer - crash when closing window
- From: Jens Bauer <email@hidden>
- Date: Sat, 11 Oct 2003 09:12:37 +0200
Hi all,
(I've searched the archives on this, however, it doesn't look like
anyone asked about this problem before, which puzzles me..)
I have a document based application, which uses a NSTimer.
The timer frequency can be changed by the user while the application is
running.
My NSDocument subclass is a delegate of my window, and contains the
following methods, including a windowWillClose method.
In some cases, where the frequency is very low (eg. the timer executes
once per second), the window closes fine without crashing the
application, however, if I set the timer to 80 times per second (freq =
1/80), clicking the close-button of the window usually makes the app
crash.
Please note: I do not choose "Quit", I only close the window.
-Can you tell me why it crashes, and how to avoid it ?
Thanks in advance. :)
Here's the methods I implemented:
---8<-----8<-----8<-----
- (void)timerTask:(NSTimer *)aTimer
{
// Draws some graphics (say an animation of 8 images, these are
256x256 pixels)
// The drawing is done by incrementing a value and refreshing a view.
}
- (void)timerStop
{
if(timer)
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[timer invalidate];
[timer release];
timer = NULL;
}
}
- (void)timerStart
{
float frequency;
frequency = 1.0 / [speedField floatValue];
if(timer)
{
[self timerStop];
}
timer = [[NSTimer scheduledTimerWithTimeInterval:frequency target:self
selector:@selector(timerTask:) userInfo:NULL repeats:YES] retain];
}
- (void)windowWillClose:(NSNotification *)aNotification
{
[self timerStop];
}
- (void)dealloc
{
[self timerStop];
[super dealloc];
}
--->8----->8----->8-----
Love,
Jens
_______________________________________________
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.