Sending release
to an NSTimer
won't invalidate it.
If the NSTimer
is scheduled in a run loop, then the run loop retains the timer. So even when you release the (scheduled) timer, it still has a retain count larger than zero. Also, it will keep firing. If the timer's target has been deallocated, the app will probably crash when the timer fires.
When you send invalidate
to a scheduled timer, the run loop releases the timer.
If the NSTimer
is not scheduled in a run loop, then it doesn't need to be invalidated. But it's safe to send invalidate
to a timer whether it's scheduled, not scheduled, or already invalidated.
So you should send your timer invalidate
in your dealloc
method, unless you're sure it's already been invalidated.
If you created the timer using [[NSTimer alloc] initWith...]
, then you should also release it. But if you created the timer using [NSTimer timerWith...]
or [NSTimer scheduledTimerWith...]
, you should not release it, because you don't own a reference to it.