Re: Trouble with NSTimer
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