airbnb / lottie-android

Render After Effects animations natively on Android and iOS, Web, and React Native
http://airbnb.io/lottie/
Apache License 2.0
35.02k stars 5.41k forks source link

Load too many json files --> Out Of Memory #2281

Closed tuanhs0606 closed 1 year ago

tuanhs0606 commented 1 year ago

Dear,

Currently I am facing the following problem: I have about 30 json files, and currently if I need to display all 30 json files I need 30 LottieAnimationView to display 30 json files and use setRepeatCount(LottieDrawable.INFINITE). This leads to Out Of Memory problem With this case could you suggest me how to solve Out Of Memory problem or is there a way to use 30 json files displayed on 1 LottieAnimationView?

Reguards, Thank you so much!

gpeal commented 1 year ago

Can you do some profiling to determine what is using the memory? Do you have bitmaps in your animations? Lottie itself doesn't use very much memory.

tuanhs0606 commented 1 year ago
  1. Do you have bitmaps in your animations ==> yes
  2. please help me check one in them(json file) https://drive.google.com/file/d/1FFVOuew9Ryv4_TnTPJ0Wviqpynb8hamF/view?usp=sharing
gpeal commented 1 year ago

@tuanhs0606 I don't have time to look at your animation right now but, most likely, this has less to do with Lottie and more to do with bitmaps. I'd recommend using the Android Studio memory profiler to see where the memory is being used.

tuanhs0606 commented 1 year ago
  1. I'd recommend using the Android Studio memory profiler to see where the memory is being used.

==> i just check Android Studio memory profiler, when i use lines code following but memory doesn't decrease

                animationViewEffect.pauseAnimation();
                animationViewEffect.cancelAnimation();
                animationViewEffect.clearAnimation();
                animationViewEffect.removeAllAnimatorListeners();
                animationViewEffect.removeAllUpdateListeners();
               LottieCompositionFactory.clearCache(application);

==> How to clear/decrease this?

  1. Please check log cat when happen Out Of memory: java.lang.OutOfMemoryError at android.graphics.Bitmap.nativeCreate(Native Method) at android.graphics.Bitmap.createBitmap(Bitmap.java:1095) at android.graphics.Bitmap.createBitmap(Bitmap.java:1041) at android.graphics.Bitmap.createBitmap(Bitmap.java:991) at android.graphics.Bitmap.createBitmap(Bitmap.java:952) at com.airbnb.lottie.LottieDrawable.ensureSoftwareRenderingBitmap(LottieDrawable.java:1533) at com.airbnb.lottie.LottieDrawable.renderAndDrawAsBitmap(LottieDrawable.java:1486) at com.airbnb.lottie.LottieDrawable.draw(LottieDrawable.java:525) at android.widget.ImageView.onDraw(ImageView.java:1360) at android.view.View.draw(View.java:21868) at android.view.View.updateDisplayListIfDirty(View.java:20741)

image

gpeal commented 1 year ago

Can you set the render mode to hardware?

tuanhs0606 commented 1 year ago

@gpeal Sorry I haven't been able to go online and reply to you for the past few days

Can you set the render mode to hardware? ==> Yes, I also tried with this setting but it still happen OOM problem animationView.setRenderMode(RenderMode.HARDWARE);

Please check the json file with more size than I am using(About 14Mb): https://drive.google.com/file/d/1XhUESPey7IjGq5xfTF59ofpZaPvJ81nb/view?usp=sharing

. Thank you!

tuanhs0606 commented 1 year ago

@gpeal Could you help me about my problem above?

gpeal commented 1 year ago

@tuanhs0606 Because I work on Lottie on nights and weekends and I'm the sole maintainer, I prioritize requests from sponsors. For a request like this, I have a queue of Lottie work that I get through and will only get to this once it bubbles up to the top.

snehilrx commented 1 year ago

@tuanhs0606 Can you share the preview of screen that you are trying to build using layout inspector. I think this issue maybe due to not using recyclerview or not using recyclerview properly (recyclerview with wrap content inside nested scrollview)

gpeal commented 1 year ago

I fixed a likely unrelated bug I discovered while taking a look at your animation. However, you have 181 720p bitmaps in your animation. Lottie is meant to be a vector renderer. If you're going to load effectively png sequences, you're likely better off with something else.

tuanhs0606 commented 1 year ago

@gpeal Thanks for your support. I check memory in app by use Profiler tool. I see the following:

Can you help me explain?

gpeal commented 1 year ago

None of those will help you as long as you are rendering your animation because your animation itself loads like 600mb of bitmaps.

tuanhs0606 commented 1 year ago

@gpeal Thank you. Could you help me suggest me any other way show like lottie view and set background color to transparent?

b1tb1t commented 4 months ago

I have same issue, native bitmap memory 200MB, I use reflect call LottieImageAsset bitmap recycle or After the animation ends, directly set a new empty resource lottieAnimView.setAnimation(R.raw.empty) "{}"

OhPeterPan commented 1 week ago

我有同样的问题,本机位图内存 200MB,我使用反射调用 LottieImageAsset 位图回收 或 动画结束后直接设置一个新的空资源 lottieAnimView.setAnimation(R.raw.empty)

What is the Empty file format? I created a.json file, but it directly triggered the crash

b1tb1t commented 5 days ago

我有同样的问题,本机位图内存 200MB,我使用反射调用 LottieImageAsset 位图回收 或 动画结束后直接设置一个新的空资源 lottieAnimView.setAnimation(R.raw.empty)

What is the Empty file format? I created a.json file, but it directly triggered the crash

"{}"