已经开启了ARC dealloc 还可以用?

发布于 2022-08-24 09:20:15 字数 101 浏览 11 评论 0

我的工程已经开启ARC了,但是我看-(void)dealloc还是可以实现的,那这个方法还是会被调用吗?还是就是个摆设?
什么时候会调用它?ARC都开起来了,这个留着还有什么用

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

熟人话多 2022-08-31 09:20:15

官方文档说得很清楚http://developer.apple.com/library/ma...

You may implement a dealloc method if you need to manage resources other than releasing instance variables. You do not have to (indeed you cannot) release instance variables, but you may need to invoke [systemClassInstance setDelegate:nil] on system classes and other code that isn’t compiled using ARC.

用来在dealloc的时候手动解除delegate关系。

貪欢 2022-08-31 09:20:15

dealloc当然会被调用(通常是以被编译器自动插入代码的方式),也可以实现(尤其是如果有某些非Cocoa对象资源需要管理的时候)。

ARC_Illustration.jpg

参考 CLANG 相关文档

执手闯天涯 2022-08-31 09:20:15

仍会在对象彻底释放前调用dealloc方法。

ARC与非ARC的区别:ARC中dealloc中不得显式调用[super dealloc]、不得显式[obj release]。

而无需声明(编译自动生成)dealloc是SDK4就有的特性,和ARC无关。

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文