FinalizationRegistry() constructor

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2021.

The FinalizationRegistry() constructor creates FinalizationRegistry objects.

Syntax

js
new FinalizationRegistry(callbackFn)

Note: FinalizationRegistry() can only be constructed with new. Attempting to call it without new throws a TypeError.

Parameters

callback

A function to be invoked each time a registered target value is garbage collected. Its return value is ignored. The function is called with the following arguments:

heldValue

The value that was passed to the second parameter of the register() method when the target object was registered.

Examples

Creating a new registry

You create the registry passing in the callback:

js
const registry = new FinalizationRegistry((heldValue) => {
  // …
});

Specifications

Specification
ECMAScript® 2027 Language Specification
# sec-finalization-registry-constructor

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Bun
Deno
Node.js
FinalizationRegistry() constructor
Chrome – Full support
Chrome 84 (Release date: 2020-07-27)
footnote Full support
Edge – Full support
Edge 84 (Release date: 2020-07-16)
footnote Full support
Firefox – Full support
Firefox 79 (Release date: 2020-07-28)
footnote Full support
Opera – Full support
Opera 70 (Release date: 2020-07-27)
footnote Full support
Safari – Full support
Safari 14.1 (Release date: 2021-04-26)
footnote Full support
Chrome Android – Full support
Chrome Android 84 (Release date: 2020-07-27)
footnote Full support
Firefox for Android – Full support
Firefox for Android 79 (Release date: 2020-07-28)
footnote Full support
Opera Android – Full support
Opera Android 60 (Release date: 2020-09-23)
footnote Full support
Safari on iOS – Full support
Safari on iOS 14.5 (Release date: 2021-04-26)
footnote Full support
Samsung Internet – Full support
Samsung Internet 14 (Release date: 2021-04-17)
footnote Full support
WebView Android – Full support
WebView Android 84 (Release date: 2020-07-27)
footnote Full support
WebView on iOS – Full support
WebView on iOS 14.5 (Release date: 2021-04-26)
footnote Full support
Bun – Full support
Bun 1 (Release date: 2023-09-08)
footnote Full support
Deno – Full support
Deno 1 (Release date: 2020-05-13)
footnote Full support
Node.js – Full support
Node.js 14.6 (Release date: 2020-07-21)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

See also