Skip to content

Commit 68ed6c7

Browse files
committed
Add compat flag docs for FinalizationRegistry and WeakRef
1 parent 1d6690c commit 68ed6c7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
_build:
3+
publishResources: false
4+
render: never
5+
list: never
6+
7+
name: "Enable `FinalizationRegistry` and `WeakRef`"
8+
sort_date: "2025-03-24"
9+
enable_date: "2025-03-24"
10+
enable_flag: "enable_weak_ref"
11+
disable_flag: "disable_weak_ref"
12+
---
13+
14+
Enables the use of [`FinalizationRegistry`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry) and [`WeakRef`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef) built-ins.
15+
* `FinalizationRegistry` allows you to register a cleanup callback that runs after an object has been garbage-collected.
16+
* `WeakRef` creates a weak reference to an object, allowing it to be garbage-collected if no other strong references exist.
17+
18+
:::note[Behaviour]
19+
`FinalizationRegistry` cleanup callbacks, if scheduled, will execute _after_ your invoked handler has returned (similar to `ctx.waitUntil()`). These callbacks do not have an associated async context — you cannot perform any I/O within them, including emitting events to a tail Worker.
20+
:::
21+
22+
:::caution
23+
These APIs are fundamentally non-deterministic — the timing and execution of garbage collection are unpredictable, and you **should not rely on them for essential program logic**. Additionally, cleanup callbacks registered with `FinalizationRegistry` may **never be executed**, including but not limited to cases where garbage collection is not triggered, or your Worker gets evicted.
24+
:::

0 commit comments

Comments
 (0)