Cloudflare

We shipped FinalizationRegistry in Workers: why you should never use it

Jun 11, 2025Ketan Gupta, Harris Hancock
We shipped FinalizationRegistry in Workers: why you should never use it
SummaryAI, from the source post

This post introduces the availability of the FinalizationRegistry API in Cloudflare Workers, detailing its purpose in managing external resources tied to garbage-collected JavaScript objects, particularly in the context of WebAssembly memory. It explains the differences in memory management between JavaScript (garbage collection) and WebAssembly (manual management), and demonstrates a pattern for using FinalizationRegistry to bridge this gap. However, it strongly advises against direct use due to the non-deterministic nature of garbage collection and highlights newer JavaScript features as more reliable solutions for preventing memory leaks and ensuring predictable resource cleanup.

More from the Edge Computing with Cloudflare Workers trail