Favorites

JavaScript FinalizationRegistry Object

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
FinalizationRegistry
JavaScript Memory Management · ConstructorThis object is supported by all modern browsers.
Updated 28th November 2026

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

const registry = new FinalizationRegistry(key => {
  console.log('Cleaned up', key);
});

let session = { user: 'Sam' };
registry.register(session, 'session-1');
session = null;
console.log('Registered; the callback runs whenever the browser collects it (maybe never)');

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.

This object is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee