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 at LottieView#setAnimationFromUrl
#2292
Comments
My guess is that this is transient and not really a leak. Lottie doesn't have a reference to the calling activity's lifecycle so it may hold a reference to its listeners until the request finishes but it should be okay once it completes. I may not have time to look at this right away and suspect that it would have come up before if it was more than a transient reference. However, if you could determine if that's the case, it would be helpful. |
Yeah, you're absolutely right - it is a transient state, but at the same time this is textbook example of a memory leak since it keeps reference to a view after the view should be garbage collected 😅 I'm not that familiar with the implementation, but I'd expect a mix of:
I might be wrong here, but if someone tried to react on a completion event after the owning parent had been destroyed (i.e. to commit a fragment transaction) it would lead to a runtime crash. So the fact it's just a temporary state doesn't fully justify keeping dead listeners 👀
Just for context, I think this was reported already here: #1753 |
A WeakRef may be useful here. This will be fairly low on my priority list since it is transient and unlikely to cause actual issues, just some LeakCanary noise. If you want to put up a PR, I could take a look. I would consider the WeakRef solution first because it requires no API changes and should cover any case. |
I took a stab at it in #2293 |
…e listeners (#2293) Fixes #2292 I followed `LeakCanary` hints, identified 2 listeners that were kept in the static map and fixed them by holding a weak reference to a target object (using private static classes). As far as I understood the flow, there should be no behavior change, other than not having a memory leak. The view can be immediately garbage collected, without altering existing behavior (the resource will continue being fetched in background).
Lottie is supported and developed on nights and weekends. Issues from Lottie sponsors will be prioritized.
If you don't use this template, your issue will be closed. Delete this text once completed.
Checklist
module may be auto-closed.
Link to fork with a repro in the issue-repro module
https://github.com/airbnb/lottie-android/compare/master...mateuszkwiecinski:lottie-android:memory_leak?expand=1 or d925e25
Describe the bug
👋
I think I spotted a memory leak happening when you call
setAnimationFromUrl
and destroy the view/activity before the resource finishes loading. If the resource fails to load or completes successfully, all resources are properly disposed, I think.Steps To Reproduce
Steps to reproduce the behavior:
don't keep activities
option, (to make sure activities are immediately destroyed)Open
buttonDump
buttonCouple of notes on the repro:
binding.root.tag = this@IssueReproActivity
to rely on default Leakcanary watchers, but again, it's unrelated to the source issue. If you start watchingLottieAnimationView
instance, it will also live after its activity is destroyed.In my original issue, the project uses databinding which sets
binding.lifecycleOwner = this
which is somewhat the same behavior I did in the reproducer.LeakCanary dump
The text was updated successfully, but these errors were encountered: