Unowned by Harmony Foundation to eliminate circular references (basic knowledge of HarmonyOS development)

What is unowned

Annotate Unowned objects to eliminate circular references.
If field members or local variables are annotated, they will not have ownership of the referenced object, and their references will not be included in the reference count of the referenced object.

Unowned supports annotations for the following common data structures: double-linked list, TreeMap and Linked HashMap.

Incorrect use of Unowned may lead to early release of referenced objects.

Taking the TreeMap data structure as an example, the parent node can be marked as "unowned" instead of left and right nodes:

   static final class TreeMapEntry<K,V> implements Map.Entry<K,V> {
       K key;
       V value;
       TreeMapEntry<K,V> left;
       TreeMapEntry<K,V> right;
       @Unowned
       TreeMapEntry<K,V> parent;
       boolean color = BLACK;
       ...;
   }
 

Unauthorized reprinting is prohibited


For more technical exchanges, please join the QQ group

Group name: harmonyos Hongmeng Technology Exchange
Group number: 856567895


Start from scratch to learn HarmonyOS Hongmeng 2.0 development

Guess you like

Origin blog.csdn.net/iCloudEnd/article/details/108640851