Hi, using iphone sdk 4.o. I am attempting to store around 10 NSTimer object in a NSMutableDictionay and then index them by key. This is to save 10 diffent startTimer, stopTimer functions. I have done like this but am worried about memory leak issues
Is the below code safe, is it ok to copy timer objects into a dict. TimerList is a property of type NSMutableDictionary.
-(IBAction)startTimer:(NSNumber)identifier
{
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:7
target:self selector:@selector(timerFireMethod:)
userInfo:nil repeats:YES];
[self.TimerList setObject:timer forKey: identifier];
}
-(IBAction)stopTimer:(NSNumber)identifier
{
NSTimer* timer = [self.ReRegisterTimerList objectForKey: identifier];
[timer invalidate];
[self.TimerList setObject:nil forKey: identifier];
}
-(void)timerFireMethod:(NSTimer*)theTimer
{
if (theTimer == [self.TimerList objectForKey:someKey])
{
found = true;
// do something if its a certain timer
}
}