Baseflow / flutter_cached_network_image

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

iOS crashed when loading thousands Images with CachedNetworkImageProvider in Listview #970

Open boomery opened 2 months ago

boomery commented 2 months ago

🐛 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:

boomery commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

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