From af054b2d6354b22b7942a9cbe32125847e9f3dd3 Mon Sep 17 00:00:00 2001 From: Dan Lapid Date: Tue, 6 May 2025 11:46:16 +0100 Subject: [PATCH] Revert "Add compat flag docs for FinalizationRegistry and WeakRef (#20668)" This reverts commit 3e3448c73eb3d88da66f69aaebd8a66469ab04b6. --- .../2025-05-05-finalization-registry.mdx | 13 ---------- .../compatibility-flags/js-weak-refs.md | 24 ------------------- 2 files changed, 37 deletions(-) delete mode 100644 src/content/changelog/workers/2025-05-05-finalization-registry.mdx delete mode 100644 src/content/compatibility-flags/js-weak-refs.md diff --git a/src/content/changelog/workers/2025-05-05-finalization-registry.mdx b/src/content/changelog/workers/2025-05-05-finalization-registry.mdx deleted file mode 100644 index 4e8f966c3c6bd4e..000000000000000 --- a/src/content/changelog/workers/2025-05-05-finalization-registry.mdx +++ /dev/null @@ -1,13 +0,0 @@ ---- -title: Improved Memory Efficiency for WebAssembly Workers -description: With the introduction of FinalizationRegistry in Workers Runtime, toolchains like Emscripten and wasm-bindgen can automatically reclaim unused WebAssembly heap and reduce memory leaks. -products: - - workers -date: 2025-05-05T00:00:00Z ---- - -[FinalizationRegistry](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry) is now available in Workers. You can opt-in using the [`enable_weak_ref`](/workers/configuration/compatibility-flags/#enable-finalizationregistry-and-weakref) compatibility flag. - -This can reduce memory leaks when using WebAssembly-based Workers, which includes [Python Workers](/workers/languages/python/) and [Rust Workers](/workers/languages/rust/). The FinalizationRegistry works by enabling toolchains such as [Emscripten](https://emscripten.org/) and [wasm-bindgen](https://rustwasm.github.io/wasm-bindgen/) to automatically free WebAssembly heap allocations. If you are using WASM and seeing Exceeded Memory errors and cannot determine a cause using [memory profiling](/workers/observability/dev-tools/memory-usage/), you may want to enable the FinalizationRegistry. - -For more information see the [`enable_weak_ref`](/workers/configuration/compatibility-flags/#enable-finalizationregistry-and-weakref) compatibility flag documentation. diff --git a/src/content/compatibility-flags/js-weak-refs.md b/src/content/compatibility-flags/js-weak-refs.md deleted file mode 100644 index eef7c4cb1ab8c29..000000000000000 --- a/src/content/compatibility-flags/js-weak-refs.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -_build: - publishResources: false - render: never - list: never - -name: "Enable `FinalizationRegistry` and `WeakRef`" -sort_date: "2025-05-05" -enable_date: "2025-05-05" -enable_flag: "enable_weak_ref" -disable_flag: "disable_weak_ref" ---- - -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. -* `FinalizationRegistry` allows you to register a cleanup callback that runs after an object has been garbage-collected. -* `WeakRef` creates a weak reference to an object, allowing it to be garbage-collected if no other strong references exist. - -:::note[Behaviour] -`FinalizationRegistry` cleanup callbacks may execute at any point during your request lifecycle, even after your invoked handler has completed (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. -::: - -:::caution -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. -::: \ No newline at end of file