Loading topic
WeakRef and FinalizationRegistry correctly, you first need to know how the engine decides that an object is "no longer needed", and why you cannot predict when that happens.2 min readMap and Set work, and that an object is collected once nothing reachable points to it. WeakRef and FinalizationRegistry arrived in ES2021. Before that, WeakMap and WeakSet (ES2015) were the only weak structures in the language.2 min readSymbol(), and that you have read the earlier chapters on WeakRef and deref(). The examples need Node.js 20 or later, or a current browser.2 min readWeakRef and call deref(), and that you understand the event loop, tasks, and microtasks at a conceptual level. It covers one rule that makes deref() safe to use: a target you have just observed cannot disappear in the middle of your synchro2 min readWeakRef, which lets you check whether an object still exists. FinalizationRegistry covers the opposite need. I2 min readFinalizationRegistry and call register(), and that you understand reachability and the difference between strong and weak references from the earlier chapters.2 min readFinalizationRegistry, call register(), and pass a held value to the cleanup callback. Here you will learn how to cancel a registration once the callback is no longer needed.2 min readWeakRef, call deref(), and register objects with a FinalizationRegistry. It also assumes you understand the event loop at a conceptual level, in particular what a "job" (one run of synchronous code from start to finish) is. The topic here i2 min readWeakRef and deref() work, how FinalizationRegistry passes a held value to its callback, and how Map works. Here those pieces are combined into one common pattern: a cache that does not keep its values alive.2 min readFinalizationRegistry, held values, and unregister tokens work, and that the engine gives no guarantee about when or whether cleanup callbacks run. Here we put those pieces together into one practical pattern: a backup cleanup path for resources that live o2 min readWeakRef, deref(), and FinalizationRegistry work from earlier chapters. It also assumes you can run scripts with Node.js and open browser DevTools. The aim is to see collection happen during experiments. It does not show you how to rely on it.2 min readFinalizationRegistry, unregister tokens, and the timing guarantees the engine does not make. It also assumes you are comfortable with try/finally and classes.2 min read