简体   繁体   English

ARC 工作方法和强、弱和 UnOwned 引用的必要性

[英]ARC working method and Necessity of Strong, Weak and UnOwned references

I was facing problem with deallocation of View Controller in my code, then I read about how ARC work and about Strong, Weak and UnOwned references.我在代码中面临解除分配视图控制器的问题,然后我阅读了 ARC 的工作原理以及强、弱和未拥有的引用。 I was wondering, why swift has made it so complicated?我想知道,为什么 swift 让它变得如此复杂? deallocation problem could be solved using slightly different method than what ARC method does.可以使用与 ARC 方法略有不同的方法来解决解除分配问题。 Here is my method:这是我的方法:

We can think dependency between objects as directed graph, and can find an unReachable part of graph from current location using proper(using flags) BFS search(in O(n)), and then we can de-initialise all instances which are in unreachable part of graph.我们可以将对象之间的依赖视为有向图,并且可以使用适当的(使用标志)BFS 搜索(在 O(n) 中)从当前位置找到图的不可到达部分,然后我们可以取消初始化所有不可到达的实例图的一部分。 Then we can directly work with strong references and there will be no need for weak or unowned references.然后我们可以直接使用强引用,并且不需要弱引用或无主引用。

Am I missing something here?我在这里错过了什么吗? May be some performance issue or some limitations.可能是一些性能问题或一些限制。 Can someone please give me a reason for necessity of Strong, Weak and UnOwned references or some article/document which can explain reason for above in detail?有人可以给我一个需要强、弱和未拥有的引用的理由或一些可以详细解释上述原因的文章/文件吗?

This is the official documentation and this is a more entertaining discussion .这是官方文档,这是一个 更有趣的讨论 For the most part ARC stays out of your way, just requiring some hints eg when creating closures that reference self but execute in the context of another component.在大多数情况下,ARC 不会妨碍您,只需要一些提示,例如在创建引用 self 但在另一个组件的上下文中执行的闭包时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM