Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak in animations #25001

Open
owl-guy opened this issue Sep 30, 2024 · 7 comments · May be fixed by #25232 or #26143
Open

Memory leak in animations #25001

owl-guy opened this issue Sep 30, 2024 · 7 comments · May be fixed by #25232 or #26143
Labels
area-animation Animation, Transitions, Transforms memory-leak 💦 Memory usage grows / objects live forever (sub: perf) platform/android 🤖 platform/iOS 🍎 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working t/perf The issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf)
Milestone

Comments

@owl-guy
Copy link

owl-guy commented Sep 30, 2024

Description

When creating an animation that repeats, new TweenerAnimation Objects are created continuously, filling up the app's memory. If you leave it going long enough, the app will crash.

The provided sample repo includes two memory dumps, one was taken after the app was started, the other one after a few minutes. A diff comparison shows an increase in TweenerAnimation objects:
image

Steps to Reproduce

  1. Create a new .NET MAUI Project
  2. Commit an animation that repeats itself (let repeat function be () => true)
  3. Start the app with profiler enabled
  4. Take a memory dump
  5. Leave the app running for a few minutes
  6. Take another memory dump and compare with the first one. The number of TweenerAnimation objects will have increased a lot

Link to public reproduction project repository

https://github.com/owl-guy/PerfTest

Version with bug

8.0.91 SR9.1

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

@owl-guy owl-guy added the t/bug Something isn't working label Sep 30, 2024
@jfversluis jfversluis added area-animation Animation, Transitions, Transforms t/perf The issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf) memory-leak 💦 Memory usage grows / objects live forever (sub: perf) labels Sep 30, 2024
@jfversluis
Copy link
Member

@jonathanpeppers FYI

@jonathanpeppers
Copy link
Member

I remember this happening for me in a production app in Xamarin.Forms, circa 2016 as well. But I can't find an issue on this.

We took the approach:

  • Instead of () => true for repeating animations...
  • Use a CancellationToken and CancellationTokenSource like () => cts.Token.IsCancellationRequested
  • The outermost Page calls CancellationTokenSource.Cancel() in the appropriate place. OnDisappearing() seems like a good option.

With this in place, does the problem go away?

@owl-guy
Copy link
Author

owl-guy commented Oct 1, 2024

@jonathanpeppers i will try this out, but the problem is that we have views in our app that act as display screens, which means the user will stay in that view for days or even weeks while it's being animated. Your suggestion will not help for this case.

@jonathanpeppers
Copy link
Member

@owl-guy if you have a more appropriate place to call CancellationTokenSource.Cancel(), do that. If the animation is not currently on the screen, you should cancel it.

@owl-guy
Copy link
Author

owl-guy commented Oct 1, 2024

@jonathanpeppers i understand, but our problem arises because the animation is on the screen for a long time. If you leave the view with the animation open long enough, the app will crash because it's running out of memory

@Alex-111
Copy link

Alex-111 commented Oct 7, 2024

It seems to be on all platforms. Just tested with Windows....

@Zhanglirong-Winnie Zhanglirong-Winnie added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Oct 12, 2024
@Zhanglirong-Winnie
Copy link

This issue has been verified using Visual Studio 17.12.0 Preview 2.1(8.0.82 & 8.0.91 & 8.0.90). Can repro this issue on windows, android and ios platforms.

@pictos pictos linked a pull request Oct 13, 2024 that will close this issue
@jsuarezruiz jsuarezruiz added this to the Backlog milestone Oct 14, 2024
@pictos pictos linked a pull request Nov 27, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-animation Animation, Transitions, Transforms memory-leak 💦 Memory usage grows / objects live forever (sub: perf) platform/android 🤖 platform/iOS 🍎 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working t/perf The issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants