• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSTimer - crash when closing window
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: NSTimer - crash when closing window
      • From: "Alastair J.Houghton" <email@hidden>
  • Prev by Date: How does NSTableView decide to tell an NSCell to highlight on and after mouseDown?
  • Next by Date: Re: NSTimer - crash when closing window
  • Previous by thread: How does NSTableView decide to tell an NSCell to highlight on and after mouseDown?
  • Next by thread: Re: NSTimer - crash when closing window
  • Index(es):
    • Date
    • Thread