Baseflow / flutter_cached_network_image

Download, cache and show images in a flutter app
https://baseflow.com
2.43k stars 653 forks source link

perf: memory Memory Overflow Issue due to CachedNetworkImage #429

Open pranavkpr1 opened 4 years ago

pranavkpr1 commented 4 years ago

Hi, Allez gezellig! Thanks for creating this plugin. I was really concerned about my app crashes and then I did memory profiling on the app. And I am attaching the screenshots of heap dumps here. I have used Cached Network Image in my entire project and have not used Network. Image or any other plugin. As you can see that the images/ Cached Network Image is responsible for app crashes and out of memory errors. I have also read the similar issues here in issues section for the plugin. And now I am reading even Network.Image or ImagePicker causes the same kind of behavior if used without cacheWidth/width and cacheHeight. I think flutter team should update their official docs for these plugins/libraries so that unexpected behavior is not triggered causing the production app to crash if developers used these plugins without any recommendations to reduce memory consumption in the heap. It's also important to mention in Readme for this plugin to use all recommended measures such as memWidth, memHeight or use the 2.3.0 beta version so that future developers can use this plugin effectively to add multiple images in the app. It would be also helpful if you can elaborate on all these recommended measures here or update the Readme so that it can help the future developers. I also tried using 2.3.0-beta.1 in android app because that't the latest version on stable flutter channel. I also tried adding memWidth and memHeight parameters to CachedNetworkImage. But to no avail. That's why need some recommendations from the contributors. I saw the code for CachedNetwork image too and it's using default cache manager from flutter cache manager package if not provided with cache manager as parameter. The only thing that now I could try is to limit the maximum number of cache objects for Cache Manager which is passed as parameter to the Cached Network Image. So my question to the team are as follows:

  1. What's the maximum number of cache objects that default cache manager can hold because in my code, I have seen it increasing to 600-700 object levels in heap dump which would definitely crash the app frequently. While looking at the code for default cache manager in this link https://github.com/Baseflow/flutter_cache_manager/blob/develop/flutter_cache_manager/lib/src/cache_manager.dart I observed that max duration is set to 30 days and max number of objects is set at 200 for Default Cache Manager. As I am using Cached network image in number of places in my code so that's why it might be going to 600-700 level. Is it recommend to use Cache Manager as global variable in the code and then pass that global Cache Manager as parameter to different instances of Cached Network Image?
  2. And what should be the ideal number of cache objects we should limit the cache manager to, if that global cache manager is passed as parameter to Cached Network Image.
    Looking forward to the reply. Dank je wel!

snapshot1 snapshot2 snapshot3 snapshot7 snapshot8 snapshot9 snapshot10 snapshot11

Qingx commented 3 weeks ago

any update?

huythao99 commented 1 week ago

any update?

boomery commented 1 day ago

same problem, anyone has solution ?