Skip to content

Fix AnimationManager.Dispose — retained ticker keeps disposed manager and callbacks alive - #37639

Merged
kubaflo merged 5 commits into
dotnet:inflight/currentfrom
HarishwaranVijayakumar:fix-37228
Aug 20, 2026
Merged

kubaflo merged 5 commits into
dotnet:inflight/currentfrom
HarishwaranVijayakumar:fix-37228

Conversation

@HarishwaranVijayakumar

Copy link
Copy Markdown
Contributor

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

  • 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

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

Fixes #37228

Tested the behavior in the following platforms

  • Windows
  • Android
  • iOS
  • Mac

Output

Before After

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 37639

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 37639"

@dotnet-policy-service dotnet-policy-service Bot added the community ✨ Community Contribution label Aug 19, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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.

@dotnet-policy-service dotnet-policy-service Bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Aug 19, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

@sheiksyedm

Copy link
Copy Markdown
Contributor

/azp run maui-pr-uitests , maui-pr-devicetests

@sheiksyedm
sheiksyedm marked this pull request as ready for review August 19, 2026 13:10
Copilot AI lite review requested due to automatic review settings August 19, 2026 13:10
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI 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.

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 the Ticker.Fire callback, 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.

@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added s/agent-review-in-progress AI review is currently running for this PR and removed s/agent-review-in-progress AI review is currently running for this PR labels Aug 19, 2026
Copilot AI review requested due to automatic review settings August 20, 2026 05:26

Copilot AI 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.

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; }

@vishnumenon2684

Copy link
Copy Markdown
Contributor

/azp run maui-pr-uitests , maui-pr-devicetests

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).

@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Aug 20, 2026
@kubaflo
kubaflo changed the base branch from main to inflight/current August 20, 2026 14:49
@kubaflo
kubaflo merged commit 30fd5f5 into dotnet:inflight/current Aug 20, 2026
163 of 168 checks passed
@github-actions github-actions Bot added this to the .NET 10 SR11 milestone Aug 20, 2026

@MauiBot MauiBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

AI Review Summary

@HarishwaranVijayakumar — new AI review results are available based on commit dcef797.

Gate No Tests Confidence High Platform All


🗂️ 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

  • AnimationManager assigns OnFire to ITicker.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 implementing IDisposable.
  • The added AnimationManagerTests cover callback release, payload collection, multicast callback preservation, ticker stop/dispose counts, and avoiding animation callback/disposal side effects.
  • Inline review requested a nullable TestTicker.Fire contract 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, so EstablishBrokenBaseline.ps1 may report No 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: ⚠️ SKIPPED — the completed gate reported no detected tests; it was not rerun.

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 ⚠️ SKIPPED (Gate) 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

  1. Major — active animations are abandoned. _animations.Clear() skips ForceFinish(), RemoveFromParent(), and completion callbacks. Controls animation tasks can remain incomplete and static animation registries can retain stale entries. The existing ForceFinishAnimations() primitive should be used after detaching OnFire.
  2. Major — use after disposal can silently hang. Add() remains callable after Dispose(), 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.
  3. 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.
  4. 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 ⚠️ BLOCKED 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 ⚠️ BLOCKED 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 ⚠️ SKIPPED (Gate) 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: ⚠️ BLOCKED before editing. 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: ⚠️ BLOCKED before editing. 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 ⚠️ Gate skipped; no trusted test result 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 ⚠️ Blocked; empty diff; not tested 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 ⚠️ Blocked; empty diff; not tested 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 ObjectDisposedException from Add() after disposal, preventing a restarted ticker with no manager callback.
  • Applied: Add a non-disposed GC control, exercise a non-IDisposable ticker, and cover post-disposal Add().
  • 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.

@MauiBot MauiBot added s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-fix-win AI found a better alternative fix than the PR s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review) and removed s/agent-review-in-progress AI review is currently running for this PR labels Aug 20, 2026
@kubaflo

This comment has been minimized.

kubaflo pushed a commit that referenced this pull request Aug 27, 2026
… 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.
-->
kubaflo pushed a commit that referenced this pull request Sep 2, 2026
… 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.
-->
kubaflo pushed a commit that referenced this pull request Sep 3, 2026
… 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.
-->
kubaflo pushed a commit that referenced this pull request Sep 6, 2026
… 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.
-->
kubaflo pushed a commit that referenced this pull request Sep 7, 2026
… 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.
-->
kubaflo pushed a commit that referenced this pull request Sep 8, 2026
… 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.
-->
kubaflo pushed a commit that referenced this pull request Sep 9, 2026
… 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.
-->
kubaflo pushed a commit that referenced this pull request Sep 11, 2026
… 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.
-->
kubaflo pushed a commit that referenced this pull request Sep 15, 2026
… 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.
-->
kubaflo pushed a commit that referenced this pull request Sep 18, 2026
… 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.
-->
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 20, 2026
@github-actions github-actions Bot modified the milestones: .NET 10 SR11, .NET 10 SR12 Oct 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-fix-win AI found a better alternative fix than the PR s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[leak-scan] AnimationManager.Dispose — retained ticker keeps disposed manager and callbacks alive

6 participants