WeakRef: Holding Without Keeping Alive

Bayu’s vault: a 1 MB archive, its strong holds, and the WeakRef ticket that does not keep it. A real WeakRef and FinalizationRegistry; when the browser sweeps…

Why it matters

A cache of something heavy (a big parsed file, a decoded image) may vanish when memory is needed: with a WeakRef that cache does not keep it all forever. A FinalizationRegistry helps tidy up related resources after the object is swept.

The key idea

A WeakRef holds without keeping, and the browser decides when to sweep

Common mistakes

Try it in this playground