Re: NSTimer crashing on fire
Re: NSTimer crashing on fire
- Subject: Re: NSTimer crashing on fire
- From: Jeremy Dronfield <email@hidden>
- Date: Fri, 23 Apr 2004 20:00:23 +0100
To Buddy and Fritz,
Thanks for that. I did correct the releases and setting to nil after I
sent in my post, but it didn't help. I now make sure the window and the
timer are released and set to nil after a fire. Also, instead of
invalidating the timer, I reset its fireDate. Problem persists. I've
discovered that it is in fact my selector method that's causing the
crash, though I still don't know why. I tried commenting out all the
code in my -runNagWindow: method except for an NSLog(). Result: no
crash. The timer resets, fires, resets, resets, resets, fires... etc. I
then tried commenting out bits of the method, and got it down to the
allocation of the window. This is it:
if (nagWindow == nil) {
nagWindow = [[TransparentWindow alloc] initWithContentRect:nagRect
styleMask:
NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
}
I've tried changing the backing to non-retained, but it didn't help. I
also tried using a standard NSWindow instead of the TransparentWindow
subclass, and that didn't help either.
Any idea what's going wrong here?
Regards
-Jeremy
On 23 Apr 2004, at 7:24 pm, Fritz Anderson wrote:
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.