ARC 中的弱引用清零
如果我阅读迈克·阿什的“归零”弱引用”的写法是正确的,弱引用就像没有ARC的分配
引用。但是,如果引用的对象被释放,则该指针将被设置为nil
,而不是获得“悬空指针”(即指向已释放对象的指针)。
这是正确的吗?任何标记为 weak
或 assign
的属性是否会发生这种情况(当 ARC 处于活动状态时)?
如果这是正确的,则会出现这种情况消除大量 SIGABRT。
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
.
Is this right, and does this happen with any property marked weak
or assign
(when ARC is active)?
If this is correct, this would eliminate a lot of SIGABRTs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它基本上是正确的,但是分配属性仍然像以前一样对待,只有弱属性被归零。另一个需要注意的是,归零弱引用仅在 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, onlyweak
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.