Objective c NSTimer被重新绑定,NSButton操作不被保留
我的问题是 为什么 它不是保留和删除的Objective c NSTimer被重新绑定,NSButton操作不被保留,objective-c,parent-child,strong-typing,weak,Objective C,Parent Child,Strong Typing,Weak,我的问题是 为什么 它不是保留和删除的 mytimer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(_timerFired:) userInfo
mytimer = [NSTimer scheduledTimerWithTimeInterval:1.0f
target:self
selector:@selector(_timerFired:)
userInfo:nil
repeats:YES];
是retaind,两者都有目标自我,所以一个是retain,另一个不是retaind。
@结束使用
+[NSTimer scheduledTimerWithTimeInterval:…]
创建的NSTimer
在当前运行循环上调度,运行循环本身保留计时器
如果使用分配工具评测程序并搜索CFRunLoopTimer
的活动实例,您可以看到这一点。您将看到,在对scheduledTimerWithTimeInterval:…
的调用下,有一个对CFRunLoopAddTimer
的调用,并且计时器保留在该调用下
因此,保留计时器而不保留按钮这一事实与运行循环上计时器的调度有关,与任一对象的目标无关
您可能会发现以下参考资料非常有用:
我包含了对运行循环管理的参考,但您可能不需要执行任何手动运行循环管理。对“运行循环”的含义有一个高层次的理解是很好的,因为当它出现在其他文档中时。thanx供您回复,但请解释一下,因为我是iphone开发的新手,不能理解那么深。请解释一下,如果可以的话。对引用计数系统和运行循环的合理解释对于这个答案来说太多了,但是我会添加一些链接到您可能会觉得有用的引用。
mytimer = [NSTimer scheduledTimerWithTimeInterval:1.0f
target:self
selector:@selector(_timerFired:)
userInfo:nil
repeats:YES];