flutter_cached_network_image icon indicating copy to clipboard operation
flutter_cached_network_image copied to clipboard

iOS crashed when loading thousands Images with CachedNetworkImageProvider in Listview

Open boomery opened this issue 1 year ago • 13 comments

🐛 Bug Report

Rapidly scrolling through a ListView in iOS , when i stop scrolling, the memory usage keep rising until the app crashes.

Expected behavior

The image cache usage should be kept within the restricted range.

Reproduction steps

already set the cache limit in main.dart

PaintingBinding.instance.imageCache.maximumSize = 10; PaintingBinding.instance.imageCache.maximumSizeBytes = 1024 *1024 * 100;//MB

i've used ScrollAwareImageProvider ,set maxWidth&maxHeight for CachedNetworkImageProvider

Configuration

**Version: Flutter 3.22.2 Dart 3.4.3

Platform:

  • [ ] :iphone: iOS

boomery avatar Sep 11 '24 03:09 boomery

I printed out the values using a timer and found that while the scrolling was paused, the value of PaintingBinding.instance.imageCache.liveImageCount would keep increasing, is there anyway to limit it

boomery avatar Sep 11 '24 06:09 boomery

It feels like all the picture widgets I've scrolled through are still being downloaded and cached, even though they are no longer displayed on the current screen, and they cannot be released, ultimately leading to a memory overflow.

boomery avatar Sep 11 '24 08:09 boomery

WechatIMG131

When I stop scrolling Listview after a while, pendingImageCount first increases gradually and then decreases to 0. Before pendingImageCount reaches 0, the memory usage remains in an upward state. The memory usage is released entirely when pendingImageCount reaches 0 instantaneously, just as shown in the picture

boomery avatar Sep 11 '24 08:09 boomery

Hi,

We too are facing the same issue by loading only 10 images in a listView and the web app crashes.

The issue still persists even after resizing the images. We are using the canvaskit for rendering. We do not want to use the 3rd party dependency storage for uploading/retrieving.

You can check it out the Web App, below on the Android/iOS/Windows browsers, except iOS everywhere the web app is working fine:

https://web.drnko.com/

Demo user mobile number: 1234567890 OTP: Enter 1234

Regards!

drnko avatar Dec 02 '24 14:12 drnko

Hi I getting same issue in my list view. Do you have any idea for this problem or any suggestion. Thank you so much. Then when i open detail page, it also crash again.

(I've improved some logical operation like mem cache size etc. It temprorary work but i think we need the beter solution for next time usage)

VB10 avatar Dec 06 '24 02:12 VB10

Hello, I have this same issue

ziqq avatar Dec 13 '24 06:12 ziqq

Any update on this bug???

drnko avatar Feb 28 '25 12:02 drnko

I have the same problem. After setting the errorListener parameter of CachedNetworkImageProvider to null, the problem is solved. Now I am investigating the root cause.

olers avatar Mar 19 '25 08:03 olers

hi @boomery do you have any solution to fix this? i am also facing the same problem

gj-loitp avatar May 12 '25 06:05 gj-loitp

hi @boomery do you have any solution to fix this? i am also facing the same problem

Image. you may use this widget to fix this

boomery avatar May 15 '25 06:05 boomery

Related issue here: https://github.com/Baseflow/flutter_cached_network_image/issues/830#issuecomment-2849137438

jpetro416 avatar Jul 13 '25 17:07 jpetro416

hi @boomery do you have any solution to fix this? i am also facing the same problem

Image. you may use this widget to fix this

can you show an example? what should be wrapped as a resize image??

unix14 avatar Sep 23 '25 09:09 unix14

hi @boomery do you have any solution to fix this? i am also facing the same problem

Image. you may use this widget to fix this

can you show an example? what should be wrapped as a resize image??

ResizeImage isn’t a widget you wrap around something — it’s an ImageProvider. Basically, you take your existing provider (like AssetImage, NetworkImage, etc.) and wrap it with ResizeImage, then pass it into an Image widget. For example: Image( image: ResizeImage( AssetImage("assets/large_image.png"), width: 200, height: 200, ), ) The key point: this resizes the image when decoding, so it saves memory vs. just scaling the widget with BoxFit.

liyaona avatar Sep 24 '25 01:09 liyaona