简体   繁体   English

在非 ARC 中分配并保留循环

[英]assign in NON-ARC and retain cycle

How retain cycle was tackled in NON-ARC !在非弧中如何处理保留循环!

I know assign is an alternative to weak.我知道分配是弱的替代品。

weak will have its value set to nil If object allocated is deallocated whereas assign is not如果分配的对象被解除分配而分配没有,则弱将其值设置为 nil

so how it was done earlier can anybody help me understand所以之前是怎么做的,谁能帮我理解

Zeroing weak references (what ARC calls weak ) only exist under ARC.归零弱引用(ARC 称为weak )仅存在于 ARC 下。

Non-zeroing weak references (what ARC calls unsafe_unretained ) can be used in MRC or ARC, and is the only kind of "weak reference" that is used in MRC. unsafe_unretained弱引用(ARC 称为unsafe_unretained )可用于 MRC 或 ARC,并且是 MRC 中使用的唯一一种“弱引用”。

You are asking how to avoid dangling references with non-zeroing weak references.您在问如何避免使用非零弱引用悬空引用。 You just have to design the logic of the program so that it doesn't happen.您只需要设计程序的逻辑,使其不会发生。 It's not that hard.这并不难。

Usually, a "parent" object will have strong references to "child" objects, and then a back-reference from the "child" object to the "parent" will be a weak reference (in this case a non-zeroing weak reference).通常,“父”对象将对“子”对象具有强引用,然后从“子”对象到“父”的反向引用将是弱引用(在这种情况下为非零弱引用) . All you have to do is, when the "parent" object is deallocated, in its deinitializer, nil out the back-references that the "child" objects have to it -- it can access these "child" objects since it has a reference to them.所有你需要做的是,当“父母”的对象被释放,在其deinitializer, nil出反向引用的“孩子”对象有它-它可以访问这些“孩子”对象,因为它有一个参考给他们。

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

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