FinalizationRegistry
FinalizationRegistry is a JavaScript built-in that enables running cleanup logic after an object becomes unreachable and is garbage collected. It works with weak references to avoid keeping objects alive.
A FinalizationRegistry is created with a cleanup callback: new FinalizationRegistry((heldValue) => { ... }). You register a target object by
Important semantics: finalization is non-deterministic and not guaranteed to occur in a timely manner. The callback
Common use: associating external resources (such as native handles) with a JavaScript object and releasing them
Compatibility: FinalizationRegistry was introduced in ES2021 and is supported in all major modern browsers and in