Skip to content

[web] Keep ImageSource alive until Picture disposal - #192516

Merged
auto-submit[bot] merged 5 commits into
flutter:masterfrom
harryterkelsen:fix_image_disposal_memory
Sep 11, 2026
Merged

auto-submit[bot] merged 5 commits into
flutter:masterfrom
harryterkelsen:fix_image_disposal_memory

Conversation

@harryterkelsen

Copy link
Copy Markdown
Contributor

Retains underlying ImageSource references across CanvasKit and Skwasm canvas drawing operations until the resulting Picture is disposed. This prevents premature DOM texture closure and black rendering when an image handle is disposed before rasterization.

Fixes #191800
Fixes #192347

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Retains underlying ImageSource references across CanvasKit and Skwasm
canvas drawing operations until the resulting Picture is disposed. This
prevents premature DOM texture closure and black rendering when an image
handle is disposed before rasterization.

Fixes flutter#191800
Fixes flutter#192347
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Sep 9, 2026
@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. platform-web Web applications specifically team-web Owned by Web platform team labels Sep 9, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces PictureImageTracker to track and retain ImageSource instances drawn onto a canvas during picture recording, ensuring they remain alive until the resulting picture is disposed. This tracking is integrated across CanvasKit and Skwasm canvas, picture, and recorder implementations. The review feedback identifies a type mismatch in EngineFragmentShader where a ui.Image is assigned to a map of EngineImage values, and suggests typing the map as Map<int, ui.Image> to avoid compilation errors.

Comment thread engine/src/flutter/lib/web_ui/lib/src/engine/primitives/shader.dart Outdated
mdebbar
mdebbar previously approved these changes Sep 10, 2026

@mdebbar mdebbar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread engine/src/flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/canvas.dart Outdated
Comment thread engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/picture.dart Outdated
Comment thread engine/src/flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/canvas.dart Outdated

@mdebbar mdebbar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@harryterkelsen harryterkelsen added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 10, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Sep 10, 2026
@auto-submit

auto-submit Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/192516, because - The status or check suite Mac_arm64_verify_binaries has failed. Please fix the issues identified (or deflake) before re-applying this label.

@flutter-dashboard

Copy link
Copy Markdown

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #192516 at sha ed2edbe

@flutter-dashboard flutter-dashboard Bot added the will affect goldens Changes to golden files label Sep 10, 2026
@harryterkelsen harryterkelsen added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 10, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Sep 10, 2026
Merged via the queue into flutter:master with commit 7232346 Sep 11, 2026
36 of 38 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Sep 11, 2026
@andreaspetsch

Copy link
Copy Markdown

Any chance this could go to stable (3.47.x)? #191800 is a 3.47.0 regression that hits everything using cached_network_image on web, and as far as I can see 3.47.4 (#192589) doesn't have it.

I tried git cherry-pick 7232346 onto flutter-3.47-candidate.0 to open the CP PR myself, but it conflicts in canvaskit/canvas.dart, image_source.dart, skwasm_impl/canvas.dart and image_test.dart (and shader.dart doesn't exist there yet), so it needs a manual backport.

For the CP form:

Happy to test a backport build if that helps.

auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Sep 12, 2026
Roll Flutter from 63b9518f16bc to 2553f89be1ef (62 revisions)

flutter/flutter@63b9518...2553f89

2026-09-12 [email protected] Roll clang to 07d67299a15ce03b053736e2d31a668ee0576987 (flutter/flutter#192607)
2026-09-12 [email protected] Roll Dart SDK from b24b352c29db to 7863887acbfb (3 revisions) (flutter/flutter#192665)
2026-09-12 [email protected] fix(tree): et format --all (flutter/flutter#192669)
2026-09-12 [email protected] Support activity-alias in Android launcher activity detection (flutter/flutter#187251)
2026-09-12 [email protected] fix: regenerate gradle lockfiles for external_textures integration test (flutter/flutter#192657)
2026-09-12 [email protected] Roll Skia from 51aa02b2c195 to e5e96533b732 (4 revisions) (flutter/flutter#192646)
2026-09-12 [email protected] [WebParagraph] Fix text pixelation, glyph clipping, and snapping offsets to avoid subpixel raster caching (flutter/flutter#191736)
2026-09-12 [email protected] fix(tests): Add ruby dep to Mac windowing_test (flutter/flutter#192656)
2026-09-12 [email protected] Remove some `unawaited_futures` outdated ignores (flutter/flutter#192026)
2026-09-11 [email protected] Bump Dart to 3.13, reformat, re-enable formatting check (flutter/flutter#192649)
2026-09-11 [email protected] [android] Isolate API-34 high contrast listener in AccessibilityBridge behind Api34Impl (flutter/flutter#192502)
2026-09-11 [email protected] Update style guide for Dart 3.13 (flutter/flutter#192639)
2026-09-11 [email protected] ci(bringups): remove bringup from these tests (flutter/flutter#192637)
2026-09-11 [email protected] Unmark new_gallery_windows_impeller__transition_perf as bringup (flutter/flutter#192633)
2026-09-11 [email protected] Unmark new_gallery_windows_skia__transition_perf as bringup (flutter/flutter#192635)
2026-09-11 [email protected] Roll Skia from f446aec4ce9e to 51aa02b2c195 (2 revisions) (flutter/flutter#192631)
2026-09-11 [email protected] fix(ci): mac verify binaries still racing (flutter/flutter#192634)
2026-09-11 [email protected] Roll Packages from 8a35b16 to 9caa77c (8 revisions) (flutter/flutter#192630)
2026-09-11 [email protected] Roll Dart SDK from a76fee2722e0 to b24b352c29db (2 revisions) (flutter/flutter#192627)
2026-09-11 [email protected] [tool] Migrate PackagesCommand and Pub to modular dependency injection (flutter/flutter#192460)
2026-09-11 [email protected] [tool] Migrate Darwin framework commands to modular dependency injection (flutter/flutter#192252)
2026-09-11 [email protected] [tool] Migrate Upgrade, Downgrade, and UpdatePackages commands to modular dependency injection (flutter/flutter#190787)
2026-09-11 [email protected] Roll Skia from b3fa80a0e168 to f446aec4ce9e (55 revisions) (flutter/flutter#192620)
2026-09-11 [email protected] Roll Dart SDK from d20d59cfa664 to a76fee2722e0 (2 revisions) (flutter/flutter#192616)
2026-09-11 [email protected] remove deeplink integration tests from bringup (flutter/flutter#192459)
2026-09-11 [email protected] Revert: [devicelab] Clean up Chrome profile directories and trap abort signals in web benchmarks (flutter/flutter#192615)
2026-09-11 [email protected] Roll Fuchsia Linux SDK from C0j8F-_Iy-OQZ6YyI... to m69nfK-wnHaMTe8P9... (flutter/flutter#192608)
2026-09-11 [email protected] Fix Wasm build cache mismatch in ResidentWebRunner and browser 404 fallbacks (flutter/flutter#190786)
2026-09-11 [email protected] Roll Dart SDK from 3ce3116bc9ec to d20d59cfa664 (1 revision) (flutter/flutter#192588)
2026-09-11 [email protected] [Linux] Keep the frame at the top of a resizing subsurface (flutter/flutter#192408)
2026-09-10 [email protected] [devicelab] Clean up Chrome profile directories and trap abort signals in web benchmarks (flutter/flutter#192584)
2026-09-10 [email protected] [web] Keep ImageSource alive until Picture disposal (flutter/flutter#192516)
2026-09-10 [email protected] Remove the accessibility evaluations feature flag (flutter/flutter#192266)
2026-09-10 [email protected] Promote Windows gradient benchmark tests to non-bringup (flutter/flutter#192581)
2026-09-10 [email protected] Remove commented out export in `text_input.dart` since the dart compiler has the correct behavior now (flutter/flutter#191539)
2026-09-10 [email protected] [flutter_tools] Do not mistake server-initiated requests for responses to client requests in AnalysisServer (flutter/flutter#192546)
2026-09-10 [email protected] Roll Packages from 36e088a to 8a35b16 (12 revisions) (flutter/flutter#192550)
2026-09-10 [email protected] Roll pub packages (flutter/flutter#192517)
2026-09-10 [email protected] feat(web): support --web-content-hash for entrypoint files (flutter/flutter#190153)
2026-09-10 [email protected] [web] Stop iOS auto-zoom by sizing semantic inputs at 16px (flutter/flutter#192328)
2026-09-10 [email protected] Roll Dart SDK from 0d55b7a6a9ee to 3ce3116bc9ec (2 revisions) (flutter/flutter#192534)
2026-09-10 [email protected] Update more enum instances comparison to use equality == since dart has the correct behavior now (flutter/flutter#191788)
2026-09-10 [email protected] Fix specify_nonobvious_local_variable_types lints in luci_resultdb_test.dart (flutter/flutter#192543)
2026-09-10 [email protected] Roll ICU from 8cc91d9b6ab9 to 6ebb40c59477 (1 revision) (flutter/flutter#192527)
2026-09-10 [email protected] [Linux] Make the framebuffer depth/stencil buffer optional (flutter/flutter#192156)
2026-09-10 [email protected] [Linux] Cancel input when events stop being delivered (flutter/flutter#192277)
...
@aliesdd1993-sketch

Copy link
Copy Markdown

WebGL: INVALID_VALUE: texImage2D: no image

[√] Flutter (Channel stable, 3.47.5, on Microsoft Windows [Version 10.0.26200.9457], locale en-US) [299ms]
• Flutter version 3.47.5 on channel stable at C:\src\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 6a19cca (7 days ago), 2026-09-17 14:13:22 -0400
• Engine revision af7e796
• Dart version 3.13.4
• DevTools version 2.60.0
• Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, enable-record-use, enable-swift-package-manager,
omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration

[√] Windows Version (Windows 11 or higher, 25H2, 2009) [1,009ms]

[√] Android toolchain - develop for Android devices (Android SDK version 36.0.0) [733ms]
• Android SDK at C:\Users\User\AppData\Local\Android\sdk
• Emulator version 37.1.11.0 (build_id 15917651) (CL:N/A)
• Platform android-37.0, build-tools 36.0.0
! Multiple adb binaries found. This can cause conflicts and device detection issues:
- C:\Users\User\AppData\Local\Android\Sdk\platform-tools\adb.exe
- C:\Windows\System32\adb
• Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
This is the JDK bundled with the latest Android Studio installation on this machine.
To manually set the JDK path, use: flutter config --jdk-dir="path/to/jdk".
• Java version OpenJDK Runtime Environment (build 25.0.3+-15898627-b508.16)
• All Android licenses accepted.

[√] Chrome - develop for the web [26ms]
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[X] Visual Studio - develop Windows apps [24ms]
X Visual Studio not installed; this is necessary to develop Windows apps.
Download at https://visualstudio.microsoft.com/downloads/.
Please install the "Desktop development with C++" workload, including all of its default components

[√] Connected device (3 available) [256ms]
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.26200.9457]
• Chrome (web) • chrome • web-javascript • Google Chrome 153.0.8010.53
• Edge (web) • edge • web-javascript • Microsoft Edge 153.0.4234.32

[√] Network resources [2.1s]
• All expected network resources are available.

! Doctor found issues in 1 category.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD engine flutter/engine related. See also e: labels. platform-web Web applications specifically team-web Owned by Web platform team will affect goldens Changes to golden files

Projects

None yet

4 participants