ios - 在 ARC 下,卸载 viewcontroller 时需要为所有强成员设置 nil 吗?那是必须的吗?

标签 ios memory automatic-ref-counting

假设我有一个这样的 View Controller :

@interface ControllerA : viewcontroller{
    NSString * __strong a;
}

@end

在我设置的viewDidLoad函数中

a = [[NSSString alloc] init];

在另一个 ControllerB 中,

{
    ControllerA * controllerA = [[ControllerA alloc] init];
}

controllerA的成员会被释放吗?

最佳答案

是的,a指向的字符串会在controllerA释放时释放。您不需要自己将其设置为 nil

Transitioning to ARC Release Notes当前是查找有关使用 ARC 的更多信息的地方。它提出的一个要点是,如果您的类需要做任何事情除了在实例被释放时释放实例变量,您可能仍然需要一个自定义的-dealloc。 p>

关于ios - 在 ARC 下,卸载 viewcontroller 时需要为所有强成员设置 nil 吗?那是必须的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11444988/

相关文章:

c++ - 如何在函数中释放内存

c++ - 使用cgroup来限制资源

c++ - 并行计算内存访问瓶颈

ios - 以编程方式或以图形方式设计外观,哪个更好?

ios - 将电话提供商与 Firebase 中的电子邮件提供商关联起来 (Swift)

ios - -fontWithSize 返回不同的字体对象

ios - 自定义 UIAlertView : How to prevent an Objective-C object to be released automatically by ARC or How to retain an object manually in an ARC environment

cocoa - 如何在启用 ARC 的情况下部署到 Snow Leopard

ios - 为什么在没有 ARC 的 Xcode 中切换线程时我的对象自行释放?

ios - +[AVURLAsset isPlayableExtendedMIMEType :] behaves differently when unit tested