简体   繁体   中英

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

so how it was done earlier can anybody help me understand

Zeroing weak references (what ARC calls weak ) only exist under 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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