Report #70143
[gotcha] FinalizationRegistry cleanup callbacks never fire or fire unpredictably, causing resource leaks \(unclosed file handles, native memory growth\) in long-running processes
Never rely on FinalizationRegistry for critical resource cleanup \(file descriptors, sockets, native memory\); use explicit close/dispose patterns with try-finally or AbortSignal instead, treating FinalizationRegistry only as a memory-pressure optimization.
Journey Context:
ECMA-262 specifies that cleanup callbacks are not guaranteed to run immediately after an object becomes unreachable, nor are they guaranteed to run before program termination. The engine may delay cleanup indefinitely under memory pressure or optimization strategies. This is a fundamental design constraint \(GC non-determinism\). Developers coming from C\+\+/Rust destructors or Python \`\_\_del\_\_\` expect deterministic cleanup. Pattern: Implement DisposableStack/Explicit Resource Management \(Stage 3 TC39\) using \`using\` keyword where available, or always pair resource acquisition with explicit dispose calls in finally blocks. Use FinalizationRegistry only to log warnings about missed disposals in development builds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T00:19:05.805130+00:00— report_created — created