• 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: Trouble with NSTimer
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trouble with NSTimer


  • Subject: Re: Trouble with NSTimer
  • From: Joe Schiwall <email@hidden>
  • Date: Sat, 16 Jun 2001 15:40:29 -0400

on 6/16/01 7:05 AM, Cyril Godefroy at email@hidden wrote:

> Hi,
>
> I have a timer checking for the current time and comparing it with some
> set values.. When I want to change the set values in a window, I first
> need to invalidate the timer, otherwise the window gets deallocated. So
> I use invalidate. When I close the window, I try to add a new NSTimer
> (because the other one is no more valid and there's no 'validate'
> method) And this dies on me.
> Any ideas?

Remember that if you use one of class functions, myTimer = [NSTimer ...] to
create your timer, that is is returned to you auto-released so you need to
retain it. I had a problem like this. What was strange was that while the
timer was valid, it didn't get released (even though I didn't retain it).
After I invalidated it, it was released and the next time I tried to access
it, my program crashed.

So you need to do something like:

myTimer = [[NSTimer ...] retain];

// timer does it's thing here

[myTimer invalidate];
[myTimer release];

and repeat this loop every time you create a new timer.

Hope that helps,

Joe Schiwall
MacTelligence


  • Follow-Ups:
    • Re: Trouble with NSTimer
      • From: Brian Hill <email@hidden>
References: 
 >Trouble with NSTimer (From: Cyril Godefroy <email@hidden>)

  • Prev by Date: Re: Subclassing NSString
  • Next by Date: Re: Trouble with NSTimer
  • Previous by thread: Trouble with NSTimer
  • Next by thread: Re: Trouble with NSTimer
  • Index(es):
    • Date
    • Thread