A 4000x3000 JPEG costs about 48 MB once decoded, no matter how small the widget showing it is. Put twelve of those in a scrolling list on a 3 GB Android phone and you have a process that Android's low-memory killer will end without a stack trace. Flutter image memory on low-end Android is one of the most common causes of "random" crashes we see, and it almost never shows up on a developer's flagship.
This post covers how we found it using Android vitals and heap snapshots, and the two rules we now apply by default: decode at display size, and cap the ImageCache.
What the crash looked like in Android vitals
The first signal was not a Dart exception. It was the Play Console's Android vitals showing a user-perceived crash rate concentrated on a narrow band of devices: low RAM, older Android versions, small heap limits. The reports carried no useful Dart stack. Many were not reported as crashes at all, but as the app silently returning to the launcher, which is what a low-memory kill looks like from the user's side.
Three patterns pointed away from a logic bug:
- The crashes clustered on devices with 2-3 GB of RAM and almost none on high-end hardware.
- They correlated with sessions that had scrolled a long image-heavy list, not with a particular screen entry point.
- Backgrounding and returning to the app made it worse, because the OS had already trimmed memory and the foreground process was the next candidate.
Reproducing it meant using a genuinely constrained device or emulator profile, not a Pixel. Release-mode profiling on a low-RAM device, with the DevTools memory view attached, showed the resident set climbing in steps as the list scrolled and never coming back down.
Reading the heap: decoded size, not file size
The heap snapshot made the cause obvious. The retained objects were not widgets or models. They were decoded image data held by the ImageCache, and the sizes did not match anything the UI needed.
The mistake is conceptual. Developers reason about file size: the API returns a 400 KB JPEG, which seems fine. But the decoder produces uncompressed RGBA, so memory cost is roughly width * height * 4 bytes. That 400 KB file at 4000x3000 is about 48 MB in memory. The list tile displaying it at 96x96 logical pixels (perhaps 288x288 physical pixels on a 3x device) needed about 330 KB.
Flutter's default Image.network and Image.asset decode at the source's native resolution. The widget's size constraints scale the painted result, but they do not shrink the decode. So the cache holds the huge bitmap, and the GPU texture upload adds to the pressure on top.
The default ImageCache limits made this worse than it sounds. It holds up to 1000 images and 100 MiB. The byte cap sounds protective, but a single large decode can consume a large fraction of it, causing constant eviction and re-decode churn. On a small heap, the transient decode allocation alone can be what tips the process over.
The fix: cacheWidth and an explicit cache cap
The first rule is to decode at the size you display. Flutter exposes this as cacheWidth and cacheHeight on Image, or through ResizeImage if you build the provider yourself. Setting only one dimension preserves aspect ratio, so for list thumbnails we set width and let height follow.
The shape we use is a small wrapper that converts logical size to physical pixels:
Widget thumb(BuildContext context, String url, double logicalWidth) {
final dpr = MediaQuery.devicePixelRatioOf(context);
return Image.network(
url,
width: logicalWidth,
cacheWidth: (logicalWidth * dpr).round(),
fit: BoxFit.cover,
filterQuality: FilterQuality.low,
);
}
Two details matter here. First, multiply by device pixel ratio, or thumbnails look soft on dense screens. Second, do not pass an unbounded or wildly oversized value "just in case"; the entire point is a decode that is close to what is painted. If the widget can grow (a detail view reusing the same URL), give it a separate size and accept a second cache entry. Two right-sized entries cost less than one oversized one.
The second rule is to size the ImageCache deliberately instead of inheriting the default. We set it at startup, before the first frame renders:
void main() {
WidgetsFlutterBinding.ensureInitialized();
PaintingBinding.instance.imageCache
..maximumSize = 100
..maximumSizeBytes = 40 << 20; // 40 MiB
runApp(const App());
}
The numbers are a starting point, not a law. The reasoning is that entry count and byte budget should both be set, since the count limit protects against many small images and the byte limit protects against a few large ones. We scale the byte budget down on devices reporting low memory, and keep it modest everywhere, because a cache that is too generous is just a slower way to run out of memory.
What did not work
A few things we tried first, so you can skip them:
- Calling
imageCache.clear()on a timer. It hides the symptom, causes visible flicker and re-decoding, and does nothing for the peak allocation during a decode. - Relying on
BoxFitand constrained sizes. These affect painting, not decoding. - Only shrinking the cache. With full-resolution images, a smaller byte cap just meant constant eviction while each decode still spiked memory.
The durable fix is serving appropriately sized images from the backend as well. If your API can return a thumbnail rendition, the client wins twice: less bandwidth and a smaller source to decode. That is a backend design decision, and it is far easier to make early than to retrofit.
Verifying it, and the defaults we keep
After the change, we repeated the same long-scroll session on the same low-RAM device and compared heap snapshots. Retained image memory flattened instead of climbing, and the scroll-then-background-then-return sequence stopped getting the process killed. Over the following releases, the low-memory pattern in Android vitals dropped off for the affected device band.
We now treat this as a default for list and grid screens in new Flutter apps:
- Every list or grid image gets a
cacheWidthderived from its layout width and device pixel ratio. - The ImageCache gets an explicit count and byte cap at startup.
- Profiling happens on a low-RAM device in release or profile mode, never only on a flagship or in debug.
- Image-heavy screens are checked against Android vitals after each release, not just in QA.
This is also a recurring finding in code audits: the app works fine in review, then fails in the field on hardware nobody on the team owns. Memory problems are architectural as much as they are bugs, because they depend on what the backend sends, how lists are built, and what the client assumes about its device.
At orithLabs, we build Flutter apps with native Swift and Kotlin where it counts, and we audit existing codebases for exactly this kind of field-only failure. If your Android vitals show crashes you cannot reproduce on your own phone, we are happy to take a look at the heap with you.