Skip to content

[vector_graphics] Dispose pictures decoded after their VectorGraphic is removed - #13435

Merged
auto-submit[bot] merged 2 commits into
flutter:mainfrom
mackings:vg-dispose-after-unmount
Oct 29, 2026
Merged

auto-submit[bot] merged 2 commits into
flutter:mainfrom
mackings:vg-dispose-after-unmount

Conversation

@mackings

Copy link
Copy Markdown
Contributor

If a VectorGraphic was removed while its picture was still loading, the picture was never disposed, so it leaked.

The fix caches the picture first, and lets a removed widget release it a moment later. That way, if another widget is waiting on the same load, it can still pick it up, and the picture only gets disposed when nobody is using it.

I didn't use the fix suggested in the issue because it disposes the picture too early when two widgets share a load, and the remaining one ends up drawing a disposed picture. There's a test for that case too.

Fixes flutter/flutter#190185

Pre-Review Checklist

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

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.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2

@github-actions github-actions Bot added p: vector_graphics triage-engine Should be looked at in engine triage labels Oct 26, 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 updates the vector_graphics package to version 1.2.5, addressing a memory leak that occurs when a VectorGraphic widget is removed before loading finishes. The fix ensures that loaded picture data is cached immediately and that its release is scheduled via a microtask if the widget is unmounted or the loader changes. Unit tests have been added to verify picture disposal behavior across multiple scenarios. As there are no review comments, no further feedback is provided.

@gaaclarke
gaaclarke requested a review from b-luk October 26, 2026 18:23
@b-luk b-luk added the CICD Run CI/CD label Oct 27, 2026
@loic-sharma loic-sharma added the triage-framework Should be looked at in framework triage label Oct 27, 2026
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Oct 28, 2026
@b-luk b-luk added the CICD Run CI/CD label Oct 28, 2026

@b-luk b-luk 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. Thanks, @mackings

@b-luk
b-luk requested a review from gaaclarke October 28, 2026 17:51

@gaaclarke gaaclarke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm! thanks

@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 29, 2026
@auto-submit
auto-submit Bot merged commit ccbe75f into flutter:main Oct 29, 2026
14 checks passed
flutter-zl pushed a commit to flutter-zl/flutter that referenced this pull request Oct 30, 2026
flutter/packages@0b72e92...3742a4e

2026-10-30 [email protected] [pigeon] Allow event channel
unregistration (flutter/packages#13438)
2026-10-30 [email protected] [material_ui] Fix Escape key not
closing MenuAnchor opened by tap or click (flutter/packages#13430)
2026-10-30 [email protected] manual roll and manual build and copy
(flutter/packages#13495)
2026-10-29 [email protected] [pigeon] Separate native interop Dart
bindings into a conditionally imported companion file
(flutter/packages#13393)
2026-10-29 [email protected] [image_picker_ios] PR 4/5 Migrate
the view provider, PHPicker save operation, and image utilities to Swift
(flutter/packages#13394)
2026-10-29 [email protected] Sync release-material_ui-1.9.0 to
main (flutter/packages#13479)
2026-10-29 [email protected] [material_ui]
Unskip web tests that pass on CanvasKit and Skwasm: time_picker_test
(flutter/packages#13471)
2026-10-29 [email protected] [vector_graphics]
Dispose pictures decoded after their VectorGraphic is removed
(flutter/packages#13435)
2026-10-29 [email protected]
[camera_android_x] implement CameraX RecordingStats and VideoRecordEvent
APIs (flutter/packages#13330)
2026-10-29 [email protected] Sync release-go_router-18.1.2 to
main (flutter/packages#13480)
2026-10-29 [email protected] Sync release-cupertino_ui-1.1.5 to
main (flutter/packages#13481)
2026-10-29 [email protected]
[vector_graphics_compiler] Fix em units in text positions
(flutter/packages#13388)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
gmackall pushed a commit to gmackall/flutter that referenced this pull request Nov 3, 2026
flutter/packages@0b72e92...3742a4e

2026-10-30 [email protected] [pigeon] Allow event channel
unregistration (flutter/packages#13438)
2026-10-30 [email protected] [material_ui] Fix Escape key not
closing MenuAnchor opened by tap or click (flutter/packages#13430)
2026-10-30 [email protected] manual roll and manual build and copy
(flutter/packages#13495)
2026-10-29 [email protected] [pigeon] Separate native interop Dart
bindings into a conditionally imported companion file
(flutter/packages#13393)
2026-10-29 [email protected] [image_picker_ios] PR 4/5 Migrate
the view provider, PHPicker save operation, and image utilities to Swift
(flutter/packages#13394)
2026-10-29 [email protected] Sync release-material_ui-1.9.0 to
main (flutter/packages#13479)
2026-10-29 [email protected] [material_ui]
Unskip web tests that pass on CanvasKit and Skwasm: time_picker_test
(flutter/packages#13471)
2026-10-29 [email protected] [vector_graphics]
Dispose pictures decoded after their VectorGraphic is removed
(flutter/packages#13435)
2026-10-29 [email protected]
[camera_android_x] implement CameraX RecordingStats and VideoRecordEvent
APIs (flutter/packages#13330)
2026-10-29 [email protected] Sync release-go_router-18.1.2 to
main (flutter/packages#13480)
2026-10-29 [email protected] Sync release-cupertino_ui-1.1.5 to
main (flutter/packages#13481)
2026-10-29 [email protected]
[vector_graphics_compiler] Fix em units in text positions
(flutter/packages#13388)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD p: vector_graphics triage-engine Should be looked at in engine triage triage-framework Should be looked at in framework triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[vector_graphics] ui.Picture is not disposed when decoding completes after VectorGraphic is unmounted

4 participants