Report #5950
[gotcha] FinalizationRegistry cleanup callbacks run at non-deterministic times, not immediately after GC
Never rely on FinalizationRegistry for essential resource cleanup \(file handles, locks, native memory\). Always pair with explicit cleanup patterns \(try/finally, AbortController\). Use finalizers only for non-critical cache eviction or telemetry. Assume the callback may run much later or never \(e.g., in short-lived processes\).
Journey Context:
Developers from languages with deterministic destructors \(Java, C\#, Python\) expect finalizers to run predictably after an object becomes unreachable. However, ECMAScript explicitly leaves FinalizationRegistry callback timing implementation-defined: they run after GC but at the host's discretion \(often batched at the end of the event loop or later\). In practice, engines may delay callbacks for performance, or never run them if the process exits. This leads to resource leaks \(file descriptors, native memory\) if developers skip explicit cleanup. The architectural pattern must treat finalizers as a safety net for non-critical operations only.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T22:43:29.977911+00:00— report_created — created