diff --git a/runtime/docs/gc.md b/runtime/docs/gc.md index 63a26f617ea..d7397492be2 100644 --- a/runtime/docs/gc.md +++ b/runtime/docs/gc.md @@ -205,6 +205,22 @@ container <- AllocateObject StoreInstanceField(container, value, NoBarrier) ``` +## Weakness + +The GC supports a variety of weak and ephemeral references. + +* Heap objects + * WeakReference - Weakly references a single object. + * WeakProperty - Weakly references a key. If the key is reachable, then the value is reachable. Also called an [ephemeron](https://en.wikipedia.org/wiki/Ephemeron). It is used to implement Expando (also called WeakMap). + * WeakArray - Weakly references a variable-number of objects. Used to implement weak canonical sets. + * Finalizers - Weakly references a single object, runs a callback when the object is collected. +* Non heap objects + * Dart\_WeakPersistentHandle / Dart\_FinalizableHandle - Weakly references a single object, runs a callback when the object is collected. + * The object id ring - References objects that were assigned ids by the VM service. The references are strong during a minor GC and weak during a major GC. + * Weak tables - Weakly associate objects to integers. Used to implement Dart_GetPeer, identity hashes on 32-bit architectures, and canonicalization hashes. + +As GC traces through strong references, it maintains a set of weaklings encountered. Once the worklist of strong references is empty, the set of WeakProperties is examined for any reachable keys, which add the corresponding values to the worklist. This repeats until the worklist is empty. (This is quadratic in the worst case. Previous versions of the Dart VM used the watched set optimization. In practice, things are flat.) + ## Finalizers The GC is aware of two types of objects for the purposes of running finalizers.