OGeek|极客世界-中国程序员成长平台

标题: ios - 当使用 ARC 从 UIView 调用 dealloc 时,我可以假设 ivars 仍然保留吗? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 02:52
标题: ios - 当使用 ARC 从 UIView 调用 dealloc 时,我可以假设 ivars 仍然保留吗?

我在 UIView 的一个子类上添加一个 KVO 观察者到它的一个 subview 。我对 subview 也有很强的引用。当我在 dealloc 的 subview 上调用 removeObserver 时,我可以假设 subview 仍然存在吗?我不想泄露观察者。

基本上,ARC中调用dealloc时,是在这个调用之前还是之后自动调用[super dealloc]



Best Answer-推荐答案


来自 http://clang.llvm.org/docs/AutomaticReferenceCounting.html

A class may provide a method definition for an instance method named dealloc. This method will be called after the final release of the object but before it is deallocated or any of its instance variables are destroyed. The superclass’s implementation of dealloc will be called automatically when the method returns.

所以[super dealloc]在调用子类dealloc实现之后被调用

关于ios - 当使用 ARC 从 UIView 调用 dealloc 时,我可以假设 ivars 仍然保留吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16969288/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4