Skip to content

fix: dispose queued animation frame when image completer is disposed - #1065

Merged
rickdijk merged 9 commits into
Baseflow:mainfrom
kevmo314:fix/dispose-queued-animation-frame
Oct 29, 2026
Merged

rickdijk merged 9 commits into
Baseflow:mainfrom
kevmo314:fix/dispose-queued-animation-frame

Conversation

@kevmo314

@kevmo314 kevmo314 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

✨ What kind of change does this PR introduce? (Bug fix, feature, docs update...)

Bug fix: release animated-image resources and preserve refreshed-image playback.

⤵️ What is the current behavior?

Removed images can retain decoded frames and codecs. Refreshes can revert to an older image or remain queued after a play-once animation finishes. Synchronous codec replacement during delivery can corrupt the new animation's frame count or shorten the frame just shown.

🆕 What is the new behavior (if this is a feature change)?

Framework disposal releases queued frames and active/pending codecs. Late codec results are drained and disposed without retaining the completer; producer-side cancellation remains a follow-up. A shared helper handles pending-codec ownership, and the constructor documents that ownership.

Refreshes supersede older pending images, activate after finite playback completes, and preserve displayed-frame timing during synchronous replacement. Keep-alive pause/resume behavior is preserved. Version and changelog are updated to 4.0.6.

💥 Does this PR introduce a breaking change?

No.

🐛 Recommendations for testing

  • flutter test --coverage: all 75 package tests pass.
  • flutter analyze and formatting checks for changed Dart files pass.
  • New regressions reproduce the completed-animation refresh and synchronous frame-duration failures before the fix, then pass afterward. Additional coverage verifies pending-codec aliases are disposed exactly once.
  • Independent agy review found no additional issues in this follow-up.
  • Native example builds were not run locally; check CI.

📝 Links to relevant issues/docs

Related: #1064. Producer-side cancellation across the IO and web loaders remains a follow-up optimization; draining here avoids dropping undelivered codecs.

🤔 Checklist before submitting

  • All projects build
  • Follows style guide lines (code style guide)
  • Relevant documentation was updated
  • Rebased onto current main

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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

Copilot AI balanced review requested due to automatic review settings October 26, 2026 03:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused ownership fix has targeted regression coverage for the affected disposal paths, with no unresolved issues identified.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 28, 2026 04:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Listener removal can leave a refresh codec pending indefinitely, while cancelling a subscription during codec creation can leak an undelivered codec.

2 open issues

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 28, 2026 05:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified in the resource-cleanup and animation-lifecycle changes.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 28, 2026 08:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified in the resource-cleanup changes to MultiImageStreamCompleter.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 28, 2026 08:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the resource-cleanup and animation-lifecycle changes.

No open issues 🎉

Review effort: Balanced

@rickdijk
rickdijk force-pushed the fix/dispose-queued-animation-frame branch from 4ab9102 to 49f3071 Compare October 29, 2026 10:43
Copilot AI balanced review requested due to automatic review settings October 29, 2026 10:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the resource-cleanup and animation-lifecycle changes in MultiImageStreamCompleter.

No open issues 🎉

Review effort: Balanced

Comment thread cached_network_image/CHANGELOG.md Resolved
Copilot AI balanced review requested due to automatic review settings October 29, 2026 11:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the resource-cleanup and lifecycle changes in MultiImageStreamCompleter.

No open issues 🎉

Review effort: Balanced

Comment thread cached_network_image/CHANGELOG.md Resolved
Copilot AI balanced review requested due to automatic review settings October 29, 2026 12:00
@rickdijk
rickdijk merged commit 5387cfa into Baseflow:main Oct 29, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the resource-cleanup and refreshed-image playback changes.

No open issues 🎉

Review effort: Balanced

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants