Re: NSTimer crashing on fire
Re: NSTimer crashing on fire
- Subject: Re: NSTimer crashing on fire
- From: Fritz Anderson <email@hidden>
- Date: Fri, 23 Apr 2004 13:24:09 -0500
When nagTimer fires, release it and set it to nil. Non-repeating
NSTimers invalidate themselves when they fire. Your code issues an
extra invalidate to a fired nagTimer, which amounts to an extra
release.
-- F
On 23 Apr 2004, at 12:44 PM, Jeremy Dronfield wrote:
I'm making some really elementary mistake here, but can't figure out
what it is. I've ploughed through the docs and the archives, but can't
find anything that answers this specific problem. The situation is
this: I'm using a timer to launch an Unlicensed message after a period
of inactivity (kind of similar to OmniWeb, but using a window). This
is the method called (triggered by the user making a selection in the
application's table view):
- (void)startNagTimer
{
if (nagTimer != nil) {
[nagTimer invalidate];
[nagTimer release];
}
if (nagWindow != nil) {
[nagWindow close];
[nagWindow release];
}
if (nagTimer == nil) {
nagTimer = [[NSTimer scheduledTimerWithTimeInterval:10.0 target:self
selector: @selector(runNagWindow:) userInfo:nil repeats:NO] retain];
}
}
The first time through, the timer is started. On subsequent calls
(user has clicked the table view), the timer is invalidated and
restarted. If the timer is left long enough to fire, the nag window is
launched. Then, when the table is clicked again, the window goes away.
This is where it goes wrong. After it has fired and been recreated, it
crashes when it tries to fire again.
--
Fritz Anderson
Consulting Programmer
http://resume.manoverboard.org/
_______________________________________________
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.