• 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
Re: NSTimer crashes after invalidation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: NSTimer crashes after invalidation
      • From: Rosyna <email@hidden>
References: 
 >NSTimer crashes after invalidation (From: Michael Becker <email@hidden>)

  • Prev by Date: Re: Formatting integer value
  • Next by Date: Re: NSTimer crashes after invalidation
  • Previous by thread: Re: NSTimer crashes after invalidation
  • Next by thread: Re: NSTimer crashes after invalidation
  • Index(es):
    • Date
    • Thread