Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c NSTimer被重新绑定,NSButton操作不被保留_Objective C_Parent Child_Strong Typing_Weak - Fatal编程技术网

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
的调用,并且计时器保留在该调用下

因此,保留计时器而不保留按钮这一事实与运行循环上计时器的调度有关,与任一对象的目标无关

您可能会发现以下参考资料非常有用:

如果您要启动一个新项目,您当然应该使用自动引用计数(当您创建一个新项目时,默认情况下Xcode将为您启用该功能)。该系统并不能完全免除您思考程序内存使用情况的责任,但它会使事情变得更简单


我包含了对运行循环管理的参考,但您可能不需要执行任何手动运行循环管理。对“运行循环”的含义有一个高层次的理解是很好的,因为当它出现在其他文档中时。

thanx供您回复,但请解释一下,因为我是iphone开发的新手,不能理解那么深。请解释一下,如果可以的话。对引用计数系统和运行循环的合理解释对于这个答案来说太多了,但是我会添加一些链接到您可能会觉得有用的引用。
mytimer = [NSTimer scheduledTimerWithTimeInterval:1.0f
                                          target:self
                                        selector:@selector(_timerFired:)
                                        userInfo:nil
                                         repeats:YES];