Possible Duplicate:
NSTimer doesn't stop
I am using a NSTimer to update the value of a slider while a audio is playing.
if (sliderUpdateTimer) {
[sliderUpdateTimer invalidate];
sliderUpdateTimer=nil;
}
sliderUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateSliderForAudio) userInfo:nil repeats:YES];
once the audio is finished playing i am invalidating the Timer in audioPlayer delegate method.
-(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag{
NSLog(@"audioPlayerDidFinishPlaying");
[player release];
audioPlayer=nil;
[sliderUpdateTimer invalidate];
[sliderUpdateTimer release];
sliderUpdateTimer=nil;
}
The delegate method is getting called but the timer is not stopping…. I have only once thread on which i am runing the timer. But still the timer does not stop…. Any help in this regard is welcome…
First of all, you would be over releasing it and should receive EXC_BADACCESS (you’re not retaining the timer when you set it, so you shouldn’t release it either). Should only call:
Since you don’t receive a crash, it seems
sliderUpdateTimerisnilwhen callingaudioPlayerDidFinishPlaying:. User NSLog or put a breakpoint to check if this is true. If this is the case, you’re probably setting it to nil at some point, search forslideUpdateTimerand check where this might occur.