JavaScript WeakMap & WeakSet Guide
WeakRef and FinalizationRegistry provide low-level memory management tools. They allow references to objects without preventing garbage collection. The guide walks through WeakRef Basics, FinalizationRegistry, Use Cases. `new WeakRef(target)` creates a weak reference. `.deref()` returns the target object if still alive, or `undefined` if garbage collected. Use WeakRef for caches and object tracking without preventing cleanup. `new FinalizationRegistry(callback)` registers cleanup callbacks when objects are garbage collected. `register(target, heldValue)` tracks an object. `unregister(token)` removes registration. The guide is organized into 3 sections that build on each other, each pairing a prose explanation with runnable code. Browse the individual methods covered by this guide in the WeakMap & WeakSet category. Key APIs covered include WeakRef(), WeakRef.prototype.deref(), WeakSet.prototype.has(), WeakSet.prototype.delete(), WeakMap.prototype.has(), WeakMap.prototype.delete(). Related guides: Arrays, Strings, Numbers, Math, Date. This is one of 145 JavaScript guides on JS Reference — see the full list on the guides page.