在ARC中归零弱参考 [英] Zeroing Weak References in ARC

查看:165
本文介绍了在ARC中归零弱参考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我阅读Mike Ash的Zeroing Weak Referenceswriteup 是正确的,弱引用就像 assign 没有ARC的引用。然而,如果被引用的对象被释放,而不是获得悬挂指针(意味着指向被释放对象的指针),则指针被设置为 nil

If my reading of Mike Ash's "Zeroing Weak References" writeup is correct, weak references are like assign references without ARC. However, if the referenced object is deallocated, instead of getting a "dangling pointer" (meaning a pointer that points to a deallocated object), the pointer gets set to nil.

这是正确的,标记为 weak assign (当ARC处于活动状态时)

Is this right, and does this happen with any property marked weak or assign (when ARC is active)?

如果这是正确的,这将消除很多SIGABRT。 p>

If this is correct, this would eliminate a lot of SIGABRTs.

推荐答案

这是正确的,但 assign 属性仍然被视为相同曾经,只有 weak 的是归零。另一个警告是,归零弱引用仅适用于Mac OS X≥10.7和iOS≥5.其余的ARC反向移植到10.6和iOS 4,弱引用根本不能在这些操作系统上使用。

It's mostly right, but assign properties are still treated the same as they ever were, only weak ones are zeroing. Another caveat is that zeroing weak references are only available in Mac OS X ≥ 10.7 and iOS ≥ 5. While the rest of ARC was backported to 10.6 and iOS 4, weak references cannot be used at all on these OS's.

这篇关于在ARC中归零弱参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆