ios - ARC - 当 UIViewController 设置为 nil 时是否处理手势识别器和 KVO?

标签 ios automatic-ref-counting

我的问题非常简单:当 UIViewController 设置为 nil 时,手势识别器和 KVO 是否被清除?

我有一个项目,用户可以在其中创建和删除一些复杂的基于 UIViewController 的实例。它们存储在 NSMutableArray 中。

如果我只是从数组中删除实例,然后将其设置为 nil (我认为这是多余的),实例的所有 @properties 都会被清除(假设没有其他引用它们)?

编辑 当我不管理 KVO 时,我收到下面的警报(错误) - 所以我猜答案是“否”

An instance 0xce26d40 of class Track was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info: ( Context: 0x0, Property: 0x7530300> Context: 0x0, Property: 0x75320f0>

最佳答案

一个对象拥有它的“@properties”(假设它们是strongretain)。 View 拥有添加到其中的所有手势识别器。因此,当对象被释放时,其属性和识别器将被释放,如果没有其他人拥有它们,则会被释放。

键值观察者和通知观察者在释放之前需要手动取消订阅。

关于ios - ARC - 当 UIViewController 设置为 nil 时是否处理手势识别器和 KVO?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9911570/

相关文章:

ios - Facebook App Invide V4.0 通知

ios - 哪个对象的数组具有最多的特定对象

ios - NSZombie是否可能没有使用ARC指出EXC_BAD_ACCESS?

objective-c - 将 NSArray 内容转换为可变参数(使用 ARC)以与 NSString initWithFormat 一起使用

iphone - 选择选项卡栏项目时的事件

objective-c - UIImageJPEGRepresentation 给出 EXC_BAD_ACCESS

objective-c - 应用程序不释放内存,内存使用量每次都会增加一倍

objective-c - 使用 CFStringRef 和 CFRelease 进行适当的内存管理

iphone - 如果我的实现或头文件导入了非 ARC 代码,这是否意味着该文件也是非 ARC 的?

php - 将 APNS 推送通知发送到 PHP 中的多个设备 token 时出现问题