WeakRef
An object that holds a weak reference to another object; deref() returns the object, or undefined once it has been collected.
In more detail
Useful for caches of large objects that may be rebuilt. Collection timing is unpredictable, so never rely on it for program logic.
Related terms
- FinalizationRegistry — A JavaScript object that lets you register a callback to run some time after a given object has been garbage collected.
- WeakMap — A key-value collection whose keys must be objects and are held weakly, so an entry disappears when its key object is garbage collected.
- strong reference — A normal reference that keeps the object it points to alive; a weak reference does not stop garbage collection.
Taught in
- Memory Management: Garbage Collection, Memory Leaks And WeakMap — Frontend Architecture & Web Platform