Change in Isolate.kill() behavior leaves finalizers unrun on uncaught asynchronous errors
25K reputation · 25 Mar 2025, 07:39 UTC
Goal
Verify whether the Dart VM executes an isolate’s finalizers when the isolate terminates because of an uncaught asynchronous error, and determine which native memory or thread resources may remain allocated.
Constraint
In Dart SDK 2.19 and later, Isolate.kill() triggers a graceful shutdown that runs finalizers and releases native memory. However, the VM’s handling of isolates that end due to an unhandled async error does not appear to invoke the same shutdown sequence, leaving a potential leak path.
Uncertainty
It is unclear whether this behavior is intentional, a limitation of the current error‑propagation path, or a bug that will be addressed in a future SDK release.
- Does the VM call an isolate’s finalizers when termination results from an uncaught asynchronous error?
- Which types of resources (Dart‑allocated buffers, thread stacks, foreign memory via dart:ffi) are known to remain allocated in that scenario?
- What patterns or APIs should developers use to guarantee cleanup when relying on async error‑driven isolate termination?