Re: NSTimer crashes after invalidation
Re: NSTimer crashes after invalidation
- Subject: Re: NSTimer crashes after invalidation
- From: "M. Uli Kusterer" <email@hidden>
- Date: Tue, 15 Feb 2005 12:55:03 +0100
At 1:43 Uhr +0100 15.02.2005, Michael Becker wrote:
if (repaintTimer != nil) {
// This line crashes
[repaintTimer invalidate];
}
repaintTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f
target:[self documentView] selector:@selector(noLiveZoom)
userInfo:nil repeats:NO];
You need to retain the timer. Fire-once timers automatically
invalidate themselves once they have fired, and if you don't retain
the timer, that means it'll be released, and you'll have a stale
pointer lying around in your instance variable.
But it seems that if I call that method after the timer has once
fired, the indicated line crashes. The check for "repaintTimer !=
nil" will ALWAYS give a YES, telling me that the repaintTimer
variable is "something" but not nil and obviously not an NSTimer, as
sending any kind of message to it will result in a crash.
Variables will not automatically turn to NIL when the object they
point to goes out of scope. To the programming language, a pointer is
just a number, and no special treatment is applied to this number to
make sure it is in sync with the actual object. So, testing for NIL
in this case is like a broken pencil: pointless.
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden