Repository navigation
Fix AnimationManager.Dispose — retained ticker keeps disposed manager and callbacks alive - #37639
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 37639Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 37639" |
|
Hey there @@HarishwaranVijayakumar! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
|
/azp run maui-pr-uitests , maui-pr-devicetests |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Pull request overview
This PR addresses a memory-retention/leak scenario in AnimationManager.Dispose() where a long-lived ITicker could keep a disposed AnimationManager (and its active animations/closures) alive via the Fire callback.
Changes:
- Make
AnimationManager.Dispose(bool)idempotent and, on managed disposal, detach theTicker.Firecallback, stop the ticker, and clear active animations before optionally disposing the ticker. - Add unit tests validating that disposal detaches the owned callback (including from multicast delegates) and that captured payloads can be collected when the ticker outlives the manager.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Core/src/Animations/AnimationManager.cs | Updates disposal to detach ticker callback, stop, and clear animations to prevent retention when tickers outlive the manager. |
| src/Core/tests/UnitTests/Animations/AnimationManagerTests.cs | Adds regression tests for callback detachment and GC eligibility of captured payloads after disposing the manager. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/Core/tests/UnitTests/Animations/AnimationManagerTests.cs:92
- The leak scenario in #37228 is specifically a non-disposable ITicker outliving the disposed manager, but these tests only exercise a ticker that implements IDisposable. That means the most important case (where Dispose can’t rely on ticker disposal) isn’t directly covered, and could regress without being caught.
Consider adding a second test ticker that does NOT implement IDisposable and asserting after manager.Dispose(): (1) ticker.Fire no longer contains the manager callback (null or only ‘other’ callbacks), and (2) Stop was called / IsRunning is false.
class TestTicker : ITicker, IDisposable
{
public bool IsRunning { get; private set; }
public bool SystemEnabled { get; set; } = true;
public int MaxFps { get; set; } = 60;
public Action? Fire { get; set; }
|
/azp run maui-pr-uitests , maui-pr-devicetests |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
This comment has been minimized.
This comment has been minimized.
MauiBot
left a comment
There was a problem hiding this comment.
AI Review Summary
@HarishwaranVijayakumar — new AI review results are available based on commit
dcef797.
🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After Fix
Gate Result: ⚠️ SKIPPED
No tests were detected in this PR.
Recommendation: Add tests to verify the fix using the write-tests-agent.
📋 Pre-Flight — Context & Validation
Issue: #37228 - [leak-scan] AnimationManager.Dispose — retained ticker keeps disposed manager and callbacks alive
PR: #37639 - Fix AnimationManager.Dispose — retained ticker keeps disposed manager and callbacks alive
Platforms Affected: All (requested try-fix platform: Android)
Files Changed: 1 implementation, 1 unit-test
Key Findings
AnimationManagerassignsOnFiretoITicker.Fire; a long-lived ticker can therefore retain the disposed manager,_animations, and callback-captured payloads.- The PR makes disposal idempotent, removes only the manager-owned callback from
Ticker.Fire, stops the ticker, clears_animations, and disposes tickers implementingIDisposable. - The added
AnimationManagerTestscover callback release, payload collection, multicast callback preservation, ticker stop/dispose counts, and avoiding animation callback/disposal side effects. - Inline review requested a nullable
TestTicker.Firecontract and raised GC-lifetime flakiness; the nullable concern was addressed, while the author rejected the lifetime concern. - The PR was merged while this review was being initialized. The current review merge commit has no diff against the updated
origin/inflight/current, soEstablishBrokenBaseline.ps1may reportNo fix files detected; attempts must record that honestly rather than changing branches or refs.
Test Plan
Primary test: dotnet test src/Core/tests/UnitTests/Core.UnitTests.csproj --filter "FullyQualifiedName~Microsoft.Maui.UnitTests.AnimationManagerTests"
Mandatory regression tests: None supplied.
Gate:
Code Review Summary
Verdict: SKIPPED
Confidence: N/A
Errors: 0 | Warnings: 0 | Suggestions: 0
The dedicated expert pass is deferred to STEP 5b as required; STEP 5a gathered context and inspected the PR patch directly.
Fix Candidates
| # | Source | Approach | Test Result | Files Changed | Notes |
|---|---|---|---|---|---|
| PR | PR #37639 | Detach OnFire, stop the ticker, clear retained animations, and dispose an owned disposable ticker |
AnimationManager.cs, AnimationManagerTests.cs |
Original PR |
🔬 Code Review — Deep Analysis
Expert Evaluation — Raw PR Fix
Verdict: NEEDS_DISCUSSION
Confidence: High
The submitted fix correctly breaks the retained ITicker.Fire -> AnimationManager -> _animations object graph and stops the ticker during disposal. The exact raw PR diff was reviewed at base a2935e6065f6743c6f2d8957fe0a3b2ae8e26115 through head dcef797b5821f30aa662b4dc5b863200c248a9e0; unrelated trusted-pipeline overlay changes in the raw checkout were excluded.
Actionable findings
- Major — active animations are abandoned.
_animations.Clear()skipsForceFinish(),RemoveFromParent(), and completion callbacks. Controls animation tasks can remain incomplete and static animation registries can retain stale entries. The existingForceFinishAnimations()primitive should be used after detachingOnFire. - Major — use after disposal can silently hang.
Add()remains callable afterDispose(), can restart a ticker whose callback was removed, and leaves the added animation unable to advance or finish. Post-disposal behavior should be explicitly guarded. - Moderate — callback and ticker ownership are ambiguous. Construction replaces
Ticker.Fire, while disposal removes only this callback and then stops/disposes the injected ticker. Default scoped DI gives one ticker per manager, but custom shared registrations are not safe under this ownership model. - Moderate — tests miss discriminating controls. The weak-reference test has no non-disposed control proving ticker retention, and no test covers post-disposal
Add(). The assertion that disposal does not invoke completion currently codifies the animation-abandonment behavior.
Recommended consolidated refinement
Detach the manager callback, finish and unlink active animations through ForceFinishAnimations(), define guarded post-disposal behavior, make callback registration/removal symmetric where ownership permits, and add focused tests for the retained non-disposed control and post-disposal calls. No GitHub review action was posted; raw inline findings are persisted separately in inline-findings.json.
🛠️ Try-Fix — Analysis & Comparison
Fix Candidates
| # | Source | Approach | Test Result | Files Changed | Notes |
|---|---|---|---|---|---|
| 1 | claude-opus-5 / try-fix |
Replace the strong manager callback with a weak, self-detaching ticker subscription | None | Baseline script rejected the pre-existing dirty worktree; PR is also already merged into the review base | |
| 2 | gpt-5.6-sol / try-fix |
Route ticks through an opaque token and unregister the manager from a strong registry on disposal | None | Same baseline blockers; deliberately avoids weak references and self-detachment | |
| PR | PR #37639 | Detach OnFire, stop the ticker, clear retained animations, and dispose an owned disposable ticker |
2 files | Original PR; gate detector reported no tests |
Candidate 1 — Weak Self-Detaching Subscription
Approach: Replace Ticker.Fire = OnFire with a standalone subscription that holds only a WeakReference<AnimationManager>. It forwards ticks while the manager is alive and self-removes/stops when the target is gone or disposal marks it dead.
Mechanism-level difference: The PR treats missing disposal cleanup as the root cause. Candidate 1 instead removes the strong ticker-to-manager edge at construction time, so an undisposed manager could also be collected.
Result: EstablishBrokenBaseline.ps1 rejected approximately 40 pre-existing unrelated worktree changes and did not create .github/.baseline-state.json; independently, the PR had already merged into origin/inflight/current, leaving no broken baseline for the review merge commit.
Diff: Empty.
Test: dotnet test src/Core/tests/UnitTests/Core.UnitTests.csproj --filter "FullyQualifiedName~Microsoft.Maui.UnitTests.AnimationManagerTests" was not run because no candidate was safely applied.
Self-review: 0 findings against the empty diff.
Failure analysis: The try-fix edit boundary requires a successful baseline and forbids manipulating unrelated changes or branches. The approach remains conceptual and unvalidated. Restore ran and reported the accepted no-state result (Restored False); no attempt edits were made.
Candidate 2 — Strong Token Router
Approach: Install a static dispatch callback carrying an opaque numeric token and keep active token-to-manager mappings in a process-local registry. Disposal removes the registry entry, stops the ticker, and disposes it once. The retained callback then contains only an inert value token and does not retain the manager or animation graph.
Mechanism-level difference: Unlike the PR, candidate 2 would not subtract callbacks or clear animations. Unlike candidate 1, it would use neither weak references nor self-detachment: the registry intentionally roots active managers until disposal, and unregistering the token breaks the retention chain.
Result: EstablishBrokenBaseline.ps1 rejected the same pre-existing unrelated worktree changes and did not create .github/.baseline-state.json; the merged PR also leaves no broken delta against the updated review base.
Diff: Empty.
Test: dotnet test src/Core/tests/UnitTests/Core.UnitTests.csproj --filter "FullyQualifiedName~Microsoft.Maui.UnitTests.AnimationManagerTests" was not run because no candidate was safely applied.
Self-review: 0 findings against the empty diff.
Failure analysis: Without a baseline edit allow-list, the skill correctly prohibited implementation. The token-router design remains conceptual and unvalidated. Restore ran and reported the accepted no-state result (Restored False); no attempt edits were made.
Cross-Pollination
Skipped by the STEP 5a execution contract.
Exhausted: Yes — the two-candidate/model budget is complete; both candidates were blocked before implementation.
Selected Fix: PR #37639's fix (provisional) — it is the only implemented option. Neither alternative has passing test evidence, and the completed gate was skipped.
🏁 Report — Final Recommendation
⚠️ Final Recommendation: REQUEST CHANGES
Winner: pr-plus-reviewer
pr-plus-reviewer is the only candidate that combines an implemented fix with passing targeted validation and addresses the expert review's concrete lifecycle findings. The submitted PR correctly detaches OnFire, stops the ticker, and breaks the retained manager graph, but _animations.Clear() can abandon active animation state and Add() can restart a callback-less ticker after disposal.
Comparative ranking
| Rank | Candidate | Implementation | Validation | Assessment |
|---|---|---|---|---|
| 1 | pr-plus-reviewer |
PR fix plus force-finish cleanup, post-disposal guard, and discriminating non-disposable-ticker tests | ✅ 5/5 targeted tests passed | Best correctness/evidence balance; resolves both major expert findings without adopting a new global lifetime mechanism |
| 2 | pr |
Detaches OnFire, stops the ticker, clears _animations, and disposes an IDisposable ticker |
Fixes the reported retention root, but expert verdict is NEEDS_DISCUSSION because active animations are dropped and post-disposal Add() can silently hang |
|
| 3 | try-fix-1 |
Conceptual weak, self-detaching subscription | Unvalidated and changes lifetime semantics so an undisposed manager may disappear while work is active | |
| 4 | try-fix-2 |
Conceptual static token-to-manager router | Unvalidated, substantially more complex, and still depends on disposal to unregister global state |
Expert feedback disposition
- Applied: Replace raw collection clearing with
ForceFinishAnimations()so animations use the established finish/unlink path. - Applied: Throw
ObjectDisposedExceptionfromAdd()after disposal, preventing a restarted ticker with no manager callback. - Applied: Add a non-disposed GC control, exercise a non-
IDisposableticker, and cover post-disposalAdd(). - Not applied: Change constructor assignment to
Ticker.Fire += OnFire. The default registration is scoped one-to-one, while stopping/disposing the ticker still requires exclusive ownership; changing only subscription syntax would imply unsupported sharing without making it safe.
Evidence and uncertainty
The required targeted command passed all five AnimationManagerTests from the exact candidate sandbox. No mandatory regression command was supplied, and the trusted Gate for the raw PR was skipped. No Android device or full-suite run was performed; force-finishing during disposal can execute established animation completion paths, so broader callback reentrancy remains an explicit integration uncertainty rather than a reason to prefer either blocked alternative.
Because the winning changes are not present in the submitted PR HEAD, the recommendation is REQUEST CHANGES.
🧭 Next Steps — reviewer patch required (pr-plus-reviewer)
The reviewer-enhanced candidate won, so the submitted PR still needs those changes.
Why: pr-plus-reviewer preserves the submitted retention fix while using the established force-finish lifecycle and preventing post-disposal additions. It is the only candidate that addresses the expert findings and passes the required targeted validation; both try-fix alternatives are blocked, unimplemented, and untested.
Apply PRAgent/pr-plus-reviewer/reviewer.patch from the CopilotLogs
artifact (or follow the report's Required submitted-PR change), push the update, and run
the review again.
This comment has been minimized.
This comment has been minimized.
… and callbacks alive (#37639) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details - Disposing `AnimationManager` did not release the manager, active animations, or callback-captured data when its `ITicker` remained alive. ### Root Cause of the Issue - `AnimationManager` assigns `OnFire` to `Ticker.Fire` and stores active animations in `_animations`. Its previous `Dispose()` implementation only disposed tickers implementing `IDisposable`; it did not remove `OnFire`, stop a normal `ITicker`, or clear `_animations`. Consequently, a long-lived ticker could retain the entire object graph. ### Description of Change <!-- Enter description of the fix in this section --> ### Improvements to resource management and disposal: * Refactored the `Dispose` method in `AnimationManager` to ensure it is idempotent, detaches event handlers, clears animations, and disposes of the ticker only when appropriate. This prevents multiple disposals and ensures resources are released correctly. ### New unit tests for disposal behavior: * Added `AnimationManagerTests` with tests to verify: - The ticker callback is released without disposing the animation. - Animation payloads are released when the ticker outlives the manager. - The owned callback is properly removed from multicast delegates. - Correct disposal and stop counts for the ticker. - No unintended side effects on animation callbacks after disposal. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #37228 ### Tested the behavior in the following platforms - [x] Windows - [x] Android - [x] iOS - [x] Mac ### Output | Before | After | |----------|----------| | <img src="https://github.com/user-attachments/assets/fe7e8c32-eb2c-4808-bc8b-599aa7055344"> | <img src="https://github.com/user-attachments/assets/83fe5ec1-6462-4942-a461-034f3d25407b"> | <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->
… and callbacks alive (#37639) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details - Disposing `AnimationManager` did not release the manager, active animations, or callback-captured data when its `ITicker` remained alive. ### Root Cause of the Issue - `AnimationManager` assigns `OnFire` to `Ticker.Fire` and stores active animations in `_animations`. Its previous `Dispose()` implementation only disposed tickers implementing `IDisposable`; it did not remove `OnFire`, stop a normal `ITicker`, or clear `_animations`. Consequently, a long-lived ticker could retain the entire object graph. ### Description of Change <!-- Enter description of the fix in this section --> ### Improvements to resource management and disposal: * Refactored the `Dispose` method in `AnimationManager` to ensure it is idempotent, detaches event handlers, clears animations, and disposes of the ticker only when appropriate. This prevents multiple disposals and ensures resources are released correctly. ### New unit tests for disposal behavior: * Added `AnimationManagerTests` with tests to verify: - The ticker callback is released without disposing the animation. - Animation payloads are released when the ticker outlives the manager. - The owned callback is properly removed from multicast delegates. - Correct disposal and stop counts for the ticker. - No unintended side effects on animation callbacks after disposal. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #37228 ### Tested the behavior in the following platforms - [x] Windows - [x] Android - [x] iOS - [x] Mac ### Output | Before | After | |----------|----------| | <img src="https://github.com/user-attachments/assets/fe7e8c32-eb2c-4808-bc8b-599aa7055344"> | <img src="https://github.com/user-attachments/assets/83fe5ec1-6462-4942-a461-034f3d25407b"> | <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->
… and callbacks alive (#37639) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details - Disposing `AnimationManager` did not release the manager, active animations, or callback-captured data when its `ITicker` remained alive. ### Root Cause of the Issue - `AnimationManager` assigns `OnFire` to `Ticker.Fire` and stores active animations in `_animations`. Its previous `Dispose()` implementation only disposed tickers implementing `IDisposable`; it did not remove `OnFire`, stop a normal `ITicker`, or clear `_animations`. Consequently, a long-lived ticker could retain the entire object graph. ### Description of Change <!-- Enter description of the fix in this section --> ### Improvements to resource management and disposal: * Refactored the `Dispose` method in `AnimationManager` to ensure it is idempotent, detaches event handlers, clears animations, and disposes of the ticker only when appropriate. This prevents multiple disposals and ensures resources are released correctly. ### New unit tests for disposal behavior: * Added `AnimationManagerTests` with tests to verify: - The ticker callback is released without disposing the animation. - Animation payloads are released when the ticker outlives the manager. - The owned callback is properly removed from multicast delegates. - Correct disposal and stop counts for the ticker. - No unintended side effects on animation callbacks after disposal. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #37228 ### Tested the behavior in the following platforms - [x] Windows - [x] Android - [x] iOS - [x] Mac ### Output | Before | After | |----------|----------| | <img src="https://github.com/user-attachments/assets/fe7e8c32-eb2c-4808-bc8b-599aa7055344"> | <img src="https://github.com/user-attachments/assets/83fe5ec1-6462-4942-a461-034f3d25407b"> | <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->
… and callbacks alive (#37639) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details - Disposing `AnimationManager` did not release the manager, active animations, or callback-captured data when its `ITicker` remained alive. ### Root Cause of the Issue - `AnimationManager` assigns `OnFire` to `Ticker.Fire` and stores active animations in `_animations`. Its previous `Dispose()` implementation only disposed tickers implementing `IDisposable`; it did not remove `OnFire`, stop a normal `ITicker`, or clear `_animations`. Consequently, a long-lived ticker could retain the entire object graph. ### Description of Change <!-- Enter description of the fix in this section --> ### Improvements to resource management and disposal: * Refactored the `Dispose` method in `AnimationManager` to ensure it is idempotent, detaches event handlers, clears animations, and disposes of the ticker only when appropriate. This prevents multiple disposals and ensures resources are released correctly. ### New unit tests for disposal behavior: * Added `AnimationManagerTests` with tests to verify: - The ticker callback is released without disposing the animation. - Animation payloads are released when the ticker outlives the manager. - The owned callback is properly removed from multicast delegates. - Correct disposal and stop counts for the ticker. - No unintended side effects on animation callbacks after disposal. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #37228 ### Tested the behavior in the following platforms - [x] Windows - [x] Android - [x] iOS - [x] Mac ### Output | Before | After | |----------|----------| | <img src="https://github.com/user-attachments/assets/fe7e8c32-eb2c-4808-bc8b-599aa7055344"> | <img src="https://github.com/user-attachments/assets/83fe5ec1-6462-4942-a461-034f3d25407b"> | <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->
… and callbacks alive (#37639) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details - Disposing `AnimationManager` did not release the manager, active animations, or callback-captured data when its `ITicker` remained alive. ### Root Cause of the Issue - `AnimationManager` assigns `OnFire` to `Ticker.Fire` and stores active animations in `_animations`. Its previous `Dispose()` implementation only disposed tickers implementing `IDisposable`; it did not remove `OnFire`, stop a normal `ITicker`, or clear `_animations`. Consequently, a long-lived ticker could retain the entire object graph. ### Description of Change <!-- Enter description of the fix in this section --> ### Improvements to resource management and disposal: * Refactored the `Dispose` method in `AnimationManager` to ensure it is idempotent, detaches event handlers, clears animations, and disposes of the ticker only when appropriate. This prevents multiple disposals and ensures resources are released correctly. ### New unit tests for disposal behavior: * Added `AnimationManagerTests` with tests to verify: - The ticker callback is released without disposing the animation. - Animation payloads are released when the ticker outlives the manager. - The owned callback is properly removed from multicast delegates. - Correct disposal and stop counts for the ticker. - No unintended side effects on animation callbacks after disposal. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #37228 ### Tested the behavior in the following platforms - [x] Windows - [x] Android - [x] iOS - [x] Mac ### Output | Before | After | |----------|----------| | <img src="https://github.com/user-attachments/assets/fe7e8c32-eb2c-4808-bc8b-599aa7055344"> | <img src="https://github.com/user-attachments/assets/83fe5ec1-6462-4942-a461-034f3d25407b"> | <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->
… and callbacks alive (#37639) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details - Disposing `AnimationManager` did not release the manager, active animations, or callback-captured data when its `ITicker` remained alive. ### Root Cause of the Issue - `AnimationManager` assigns `OnFire` to `Ticker.Fire` and stores active animations in `_animations`. Its previous `Dispose()` implementation only disposed tickers implementing `IDisposable`; it did not remove `OnFire`, stop a normal `ITicker`, or clear `_animations`. Consequently, a long-lived ticker could retain the entire object graph. ### Description of Change <!-- Enter description of the fix in this section --> ### Improvements to resource management and disposal: * Refactored the `Dispose` method in `AnimationManager` to ensure it is idempotent, detaches event handlers, clears animations, and disposes of the ticker only when appropriate. This prevents multiple disposals and ensures resources are released correctly. ### New unit tests for disposal behavior: * Added `AnimationManagerTests` with tests to verify: - The ticker callback is released without disposing the animation. - Animation payloads are released when the ticker outlives the manager. - The owned callback is properly removed from multicast delegates. - Correct disposal and stop counts for the ticker. - No unintended side effects on animation callbacks after disposal. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #37228 ### Tested the behavior in the following platforms - [x] Windows - [x] Android - [x] iOS - [x] Mac ### Output | Before | After | |----------|----------| | <img src="https://github.com/user-attachments/assets/fe7e8c32-eb2c-4808-bc8b-599aa7055344"> | <img src="https://github.com/user-attachments/assets/83fe5ec1-6462-4942-a461-034f3d25407b"> | <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->
… and callbacks alive (#37639) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details - Disposing `AnimationManager` did not release the manager, active animations, or callback-captured data when its `ITicker` remained alive. ### Root Cause of the Issue - `AnimationManager` assigns `OnFire` to `Ticker.Fire` and stores active animations in `_animations`. Its previous `Dispose()` implementation only disposed tickers implementing `IDisposable`; it did not remove `OnFire`, stop a normal `ITicker`, or clear `_animations`. Consequently, a long-lived ticker could retain the entire object graph. ### Description of Change <!-- Enter description of the fix in this section --> ### Improvements to resource management and disposal: * Refactored the `Dispose` method in `AnimationManager` to ensure it is idempotent, detaches event handlers, clears animations, and disposes of the ticker only when appropriate. This prevents multiple disposals and ensures resources are released correctly. ### New unit tests for disposal behavior: * Added `AnimationManagerTests` with tests to verify: - The ticker callback is released without disposing the animation. - Animation payloads are released when the ticker outlives the manager. - The owned callback is properly removed from multicast delegates. - Correct disposal and stop counts for the ticker. - No unintended side effects on animation callbacks after disposal. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #37228 ### Tested the behavior in the following platforms - [x] Windows - [x] Android - [x] iOS - [x] Mac ### Output | Before | After | |----------|----------| | <img src="https://github.com/user-attachments/assets/fe7e8c32-eb2c-4808-bc8b-599aa7055344"> | <img src="https://github.com/user-attachments/assets/83fe5ec1-6462-4942-a461-034f3d25407b"> | <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->
… and callbacks alive (#37639) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details - Disposing `AnimationManager` did not release the manager, active animations, or callback-captured data when its `ITicker` remained alive. ### Root Cause of the Issue - `AnimationManager` assigns `OnFire` to `Ticker.Fire` and stores active animations in `_animations`. Its previous `Dispose()` implementation only disposed tickers implementing `IDisposable`; it did not remove `OnFire`, stop a normal `ITicker`, or clear `_animations`. Consequently, a long-lived ticker could retain the entire object graph. ### Description of Change <!-- Enter description of the fix in this section --> ### Improvements to resource management and disposal: * Refactored the `Dispose` method in `AnimationManager` to ensure it is idempotent, detaches event handlers, clears animations, and disposes of the ticker only when appropriate. This prevents multiple disposals and ensures resources are released correctly. ### New unit tests for disposal behavior: * Added `AnimationManagerTests` with tests to verify: - The ticker callback is released without disposing the animation. - Animation payloads are released when the ticker outlives the manager. - The owned callback is properly removed from multicast delegates. - Correct disposal and stop counts for the ticker. - No unintended side effects on animation callbacks after disposal. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #37228 ### Tested the behavior in the following platforms - [x] Windows - [x] Android - [x] iOS - [x] Mac ### Output | Before | After | |----------|----------| | <img src="https://github.com/user-attachments/assets/fe7e8c32-eb2c-4808-bc8b-599aa7055344"> | <img src="https://github.com/user-attachments/assets/83fe5ec1-6462-4942-a461-034f3d25407b"> | <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->
… and callbacks alive (#37639) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details - Disposing `AnimationManager` did not release the manager, active animations, or callback-captured data when its `ITicker` remained alive. ### Root Cause of the Issue - `AnimationManager` assigns `OnFire` to `Ticker.Fire` and stores active animations in `_animations`. Its previous `Dispose()` implementation only disposed tickers implementing `IDisposable`; it did not remove `OnFire`, stop a normal `ITicker`, or clear `_animations`. Consequently, a long-lived ticker could retain the entire object graph. ### Description of Change <!-- Enter description of the fix in this section --> ### Improvements to resource management and disposal: * Refactored the `Dispose` method in `AnimationManager` to ensure it is idempotent, detaches event handlers, clears animations, and disposes of the ticker only when appropriate. This prevents multiple disposals and ensures resources are released correctly. ### New unit tests for disposal behavior: * Added `AnimationManagerTests` with tests to verify: - The ticker callback is released without disposing the animation. - Animation payloads are released when the ticker outlives the manager. - The owned callback is properly removed from multicast delegates. - Correct disposal and stop counts for the ticker. - No unintended side effects on animation callbacks after disposal. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #37228 ### Tested the behavior in the following platforms - [x] Windows - [x] Android - [x] iOS - [x] Mac ### Output | Before | After | |----------|----------| | <img src="https://github.com/user-attachments/assets/fe7e8c32-eb2c-4808-bc8b-599aa7055344"> | <img src="https://github.com/user-attachments/assets/83fe5ec1-6462-4942-a461-034f3d25407b"> | <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->
… and callbacks alive (#37639) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details - Disposing `AnimationManager` did not release the manager, active animations, or callback-captured data when its `ITicker` remained alive. ### Root Cause of the Issue - `AnimationManager` assigns `OnFire` to `Ticker.Fire` and stores active animations in `_animations`. Its previous `Dispose()` implementation only disposed tickers implementing `IDisposable`; it did not remove `OnFire`, stop a normal `ITicker`, or clear `_animations`. Consequently, a long-lived ticker could retain the entire object graph. ### Description of Change <!-- Enter description of the fix in this section --> ### Improvements to resource management and disposal: * Refactored the `Dispose` method in `AnimationManager` to ensure it is idempotent, detaches event handlers, clears animations, and disposes of the ticker only when appropriate. This prevents multiple disposals and ensures resources are released correctly. ### New unit tests for disposal behavior: * Added `AnimationManagerTests` with tests to verify: - The ticker callback is released without disposing the animation. - Animation payloads are released when the ticker outlives the manager. - The owned callback is properly removed from multicast delegates. - Correct disposal and stop counts for the ticker. - No unintended side effects on animation callbacks after disposal. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #37228 ### Tested the behavior in the following platforms - [x] Windows - [x] Android - [x] iOS - [x] Mac ### Output | Before | After | |----------|----------| | <img src="https://github.com/user-attachments/assets/fe7e8c32-eb2c-4808-bc8b-599aa7055344"> | <img src="https://github.com/user-attachments/assets/83fe5ec1-6462-4942-a461-034f3d25407b"> | <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Issue Details
AnimationManagerdid not release the manager, active animations, or callback-captured data when itsITickerremained alive.Root Cause of the Issue
AnimationManagerassignsOnFiretoTicker.Fireand stores active animations in_animations. Its previousDispose()implementation only disposed tickers implementingIDisposable; it did not removeOnFire, stop a normalITicker, or clear_animations. Consequently, a long-lived ticker could retain the entire object graph.Description of Change
Improvements to resource management and disposal:
Disposemethod inAnimationManagerto ensure it is idempotent, detaches event handlers, clears animations, and disposes of the ticker only when appropriate. This prevents multiple disposals and ensures resources are released correctly.New unit tests for disposal behavior:
AnimationManagerTestswith tests to verify:Issues Fixed
Fixes #37228
Tested the behavior in the following platforms
Output