JavaScript FinalizationRegistry Object
A FinalizationRegistry lets you ask to be notified, at some point, after a registered object has been garbage-collected, so you can clean up related resources.
Description
A FinalizationRegistry lets you register objects with a callback that may run after they have been garbage-collected. Call register(target, heldValue); later the callback receives heldValue, which you can use to release something associated with the object, such as an entry in a cache.
The callback might run late, or never (for example if the page closes first), so it must only be used for optional clean-up, never for essential logic. Like WeakRef, it is an advanced feature that most code doesn't need.
If you might want to cancel the clean-up, pass a third argument to register(), an unregister token, and later call unregister(token). The held value must not be the target object itself, since holding it would keep the object alive. For releasing resources reliably, explicit methods such as close() or the using declaration are much better choices than relying on garbage collection.
Creating
new FinalizationRegistry(callback)Example
Browser Support
The following information will show you the current browser support for the FinalizationRegistry object. Hover over a browser icon to see the version that first introduced support for this object.
Desktop





Tablets & Mobile





