Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fix lifecycle retention and temporary native allocations in
javascript_darwin.Problems
JavascriptRuntime.channelFunctionsRegisteredis a static map. Disposing aJavascriptCoreRuntimereleases its native context but leaves its channel mapbehind. The
SetTimeoutcallback closes over the runtime, retaining it (andapplication callbacks) after disposal. The context-to-engine-ID map also keeps
stale entries.
after the context has been released. A pending timeout also retains its closure
until it fires, even though it checks
isDisposedbefore evaluating.and pointer output slots that are not consistently released.
Changes
cancel tracked timeouts, and clear runtime-owned Dart context maps.
replies and stop Promise polling with a Dart error on disposal.
runtime paths. Use
nullptrfor ignored optional exception outputs instead ofallocating an unused slot. Borrowed JSValueRefs are not freed or finalized.
cycles); return the JSON
nullfallback without releasing a null pointer.block and JSON-escape asynchronous error strings.
Reproduction / validation
On macOS, from
packages/javascript_darwin:flutter testAll 7 tests pass with Flutter 3.41.9. The new tests use real JavaScriptCore
contexts and cover 100 repeated context lifecycles, registry cleanup, double
disposal, isolation between runtimes, late successful/failed replies, pending
Promise polling, live async JSON replies and non-serializable JSON inputs.
Native runtime tests are skipped on non-macOS hosts.
A downstream iOS host was also tested in profile and Debug for 30 create/use/
dispose cycles with these fixes: post-GC runtime instances went from 30 retained
instances to 0. This is supporting lifecycle evidence, not a claim that all
native contexts were previously leaked or all RSS growth is now eliminated.
No downstream application code or internal device logs are included here.
Targeted analysis of the runtime and new test has no errors or warnings; eight
existing style-level infos remain. This PR does not claim repository-wide clean
analysis or overhaul every vendored low-level JSC wrapper.
Scope / compatibility
No package version bump or dependency override. Android is untouched.
Direct use after dispose now throws StateError instead of entering a released
context. Unserializable JSON values use the
nullfallback. Vendored source ispatched in place, as with the package's existing adapter changes.
Type of Change