question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MemoryLeak in LottieDrawable

See original GitHub issue

In LottieDrawable consturction method, it will auto add a annoyous update listener and refer the drawable and context, cause the activity leak. How to remove the update listener to avoid memory leak?

animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
      @Override public void onAnimationUpdate(ValueAnimator animation) {
        if (compositionLayer != null) {
          compositionLayer.setProgress(animator.getValue());
        }
      }
    });

reliao_img_1563248619472

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
gpealcommented, Aug 10, 2019

Newer versions of Lottie will unschedule the drawable when it is detached from the window.

0reactions
zjupurecommented, Jul 18, 2019

It is dumped from online data and not easy to produce. I read ValueAnimator source and have some suspects. When animator is scheduled, AnimationHandler singleton will hold the reference to ValueAnimator. Until animator is canceled or stopped, AnimationHandler will remove the reference. So it might have a case:

  1. lottie animation is playing, AnimationHandler hold it.
  2. activity is destroyed, the animation not be canceled or stopped, it will be scheduled in background util end. There will be a bit time memory leak cause that activity cannot be recycled by GC.
  3. How long the leak time is decided by animation left duration.

To avoid this case, we manually call LottieAnimationView#cacelAnimation() in activity#onDestory() lifecycle callback. It release the reference from AnimationHandler to ValueAnimation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Memory leak in lottie-web - Stack Overflow
I'm using lottie web on my front-end. But I still having problem with memory leak. When I remove all lottie, JavaScript VM instance...
Read more >
5.0.1
Dedicated memory for Lottie was always allocated. ... However, custom uses of LottieDrawable were prone to leaking infinite animators if they did not ......
Read more >
Lottie Android 5.0 - Gabriel Peal
Reduced memory consumption: In the hardware case, no new memory is allocated. · RenderMode: Lottie Compose and LottieDrawable now support setting a RenderMode....
Read more >
Lottie Android Versions - Open Source Agenda
... Use the application context in NetworkFetcher to prevent memory leaks (#1832) ... Added support for pause listeners on LottieDrawable and ...
Read more >
Java – How to set loop number of lottiefiles animation in android ...
setRepeatCount(LottieDrawable.INFINITE);// for Infinite loops ... Java – How to convert a String to an int in Java · Java – How to create...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found