Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Synchronous removal of the final listener during frame delivery can trigger double disposal or invalidate the frame reference before its duration is read.
1 open issue
What changed in this PR
This PR fixes a decoded animation-frame leak in MultiImageStreamCompleter, complementing #1064’s codec subscription cleanup.
Changes:
- Dispose and clear queued frames during final disposal while preserving keep-alive behavior.
- Add three regression tests covering queued frames and final keep-alive release.
- Bump the app-facing package to 4.0.6 and document the fix.
| File | Description |
|---|---|
cached_network_image/test/image_stream_completer_test.dart |
Add queued-frame disposal and keep-alive regression tests. |
cached_network_image/pubspec.yaml |
Bump version to 4.0.6. |
cached_network_image/lib/src/image_provider/multi_image_stream_completer.dart |
Release the queued frame during final disposal. |
cached_network_image/CHANGELOG.md |
Document the animation-frame leak fix. |
Review effort: Balanced
rickdijk
reviewed
Oct 27, 2026
rickdijk
reviewed
Oct 27, 2026
rickdijk
reviewed
Oct 27, 2026
rickdijk
reviewed
Oct 27, 2026
rickdijk
reviewed
Oct 27, 2026
rickdijk
reviewed
Oct 27, 2026
rickdijk
reviewed
Oct 28, 2026
rickdijk
reviewed
Oct 28, 2026
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.


✨ What kind of change does this PR introduce? (Bug fix, feature, docs update...)
Bug fix: release queued animation frames, codecs, and subscriptions when the image stream completer is disposed.
Removing animated images can leave a decoded frame, the active codec, and a pending refresh codec undisposed. The codec subscription also remains active. Synchronous final-listener removal during delivery can invalidate the frame before its duration is read.
🆕 What is the new behavior (if this is a feature change)?
Cleanup uses the framework's
onDisposed()hook, replacing the duplicate keep-alive counters and handle wrapper. Final disposal releases queued frames and active/pending codecs and cancels chunk events. Static callbacks drain and dispose late codec results without retaining the completer; cancelling during codec creation would drop those results undisposed. Replaced codecs are disposed, including superseded pending refreshes; stale decode results are released and stale decode errors ignored.Frame delivery transfers ownership before notifying listeners and stops decoding when the last listener removes itself, while preserving keep-alive and resume behavior. At cycle boundaries, a pending refresh is selected before pausing so it is available on resume. Codec activation drops superseded pending refreshes, including after pause/resume; synchronous codec replacement during delivery preserves the new animation's frame count. Constructor documentation makes codec ownership explicit. Shared helpers centralize queued-frame cleanup and regression-test setup. Version and changelog are updated to 4.0.6.
💥 Does this PR introduce a breaking change?
No.
🐛 Recommendations for testing
flutter test --coverage: all 71 package tests pass.flutter analyzeand formatting checks for changed Dart files pass.mainand are outside this disposal fix.📝 Links to relevant issues/docs
Related: #1064 addresses codec subscription cancellation. This PR also releases decoded frames and codecs through the framework disposal lifecycle.
🤔 Checklist before submitting