Iphone 在NSMutableDictionary中存储NSTimer对象

Iphone 在NSMutableDictionary中存储NSTimer对象,iphone,Iphone,使用iphonesdk4.o。我试图在NSMutableDictionary中存储大约10个NSTimer对象,然后按键对它们进行索引。这是为了保存10个不同的startTimer、stopTimer功能。我已经这样做了,但是我担心内存泄漏问题 下面的代码是否安全,是否可以将计时器对象复制到dict中。 TimerList是NSMutableDictionary类型的属性 -(IBAction)startTimer:(NSNumber)identifier { NSTim

使用iphonesdk4.o。我试图在NSMutableDictionary中存储大约10个NSTimer对象,然后按键对它们进行索引。这是为了保存10个不同的startTimer、stopTimer功能。我已经这样做了,但是我担心内存泄漏问题

下面的代码是否安全,是否可以将计时器对象复制到dict中。 TimerList是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                  
    }
}

注意,通过指针获取类类型实例,即它应该是
NSNumber*
而不是
NSNumber

否则对我来说很好-请记住对
-无效的特殊考虑:

您必须从安装计时器的线程发送此消息