我有关于NSTimer
的问题。见下面的代码:NSTimer保留数增加,为什么?
NSTimeInterval timeInterval = 1.0f;
SEL selector = @selector(executeDataRefresh);
NSMethodSignature *methodSignature = [[ExecuteDataRefesh class] instanceMethodSignatureForSelector:selector];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature];
[invocation setTarget:executeDataRefresh];
[invocation setSelector:selector];
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval: timeInterval invocation:invocation repeats:YES];
目的executeDataRefresh
的保留计数现在将通过1方法executeDataRefresh
的每次调用增加。所以1分钟后保留计数是60.
我知道方法retainCount
不应该使用,但是这种方法真的这个“不正确”吗?
怎么回事?
你可以添加executeDataRefresh方法的代码吗?我怀疑它与你的问题有关。 – ChristophK
如果你知道它不应该被使用,你为什么要使用它? – edo42
edo42:我有内存管理的问题,所以在绝望的尝试修复它,我开始记录retainCount ..但是,是的,你是对的,它产生了更多的问题,而不是答案。 – user521048