Bitmaps are often the largest memory-consuming objects in an app. Decoding and scaling operations are frequently on the critical path for frame rendering. Optimizing bitmap memory usage provides significant improvements in UI responsiveness, battery life, and overall stability by reducing jank, ANRs, and OOM-related process kills.
Contributors to high bitmap memory usage
Virtual memory that was never used may also be included in the calculation. If you see unexpectedly high bitmap memory usage, verify you're not allocating memory that goes unused.
Resources
Analyze bitmaps in Android Studio
Android Studio profiling for bitmaps
Use the Memory Profiler to inspect memory allocations in real-time, capture heap dumps, and analyze objects for memory leaks; additionally, use the heap analyzer to detect memory leaks, identify duplicate bitmap allocations, and visualize object retention.
Automated leak detection with LeakCanary
Integrate the LeakCanary library to automate the detection of memory leaks in your app. LeakCanary provides automatic heap analysis, identifying objects that should have been garbage collected but are still held in memory, such as bitmaps retained by destroyed components.
Bitmap Performance Documentation
These resources provide comprehensive guidance on best practices for efficient bitmap handling across different Android components.
- Optimize bitmap memory
- Bitmaps and memory
- Optimizing bitmap images (Compose)
- Manage your app's memory
Developer checklist for optimizing bitmap memory usage
To optimize bitmap memory efficiency, follow the three core principles: reduce, reuse, and recycle. For architectural defect layers, adaptive cache formulas, and library configuration snippets, see Optimize bitmap memory.
- Reduce: Minimize the initial memory footprint when loading or displaying bitmaps.
- Reuse: Consolidate image pipelines, eliminate duplicate decodes, and size caches to the active window.
- Recycle: Proactively release UI resources when your app's UI is hidden, including while running foreground services.
The following developer checklist can help you optimize bitmap memory usage.
| Core principle | Area | Description |
|---|---|---|
| Reduce | Implement container-bound downsampling | Decode images to match target UI container bounds on both your CDN and client decoder instead of loading full-resolution or full-screen assets. |
| Reduce | Prefer Bitmap.Config.HARDWARE for static UI |
Enable hardware bitmaps so immutable UI images reside in graphics memory rather than the native heap, and avoid blanket RGB_565 on photo feeds. |
| Reduce | Prioritize VectorDrawable and zero-byte backgrounds |
Use vectors for icons and ColorDrawable or Modifier.background instead of solid-color software bitmaps. |
| Reduce | Eliminate transparent margins | Avoid allocating memory for invisible border pixels by cropping margins and using InsetDrawable or layout padding. See Trim transparent margins. |
| Reuse | Consolidate onto one image loader | Standardize on a single shared image loader per process (such as Coil or Glide) to avoid duplicate LruCache pools across Views and Compose. |
| Reuse | Eliminate duplicate bitmaps | Capture lossless PNG heap dumps (adb shell am dumpheap -g -b png) or use the Memory Profiler to detect and deduplicate identical pixel buffers, including vector animation raster frames. |
| Reuse | Size caches to the active window | Bound strong memory caches to window pixel dimensions and RAM tier rather than static Java heap percentages. |
| Recycle | Configure TRIM_MEMORY_UI_HIDDEN eviction |
Configure Coil, Glide, Fresco, and Lottie to clear strong UI caches when the UI leaves the screen instead of waiting for TRIM_MEMORY_BACKGROUND. |
| Recycle | Clear UI caches under foreground services | Observe ProcessLifecycleOwner ON_STOP so UI bitmaps release even when an active foreground service keeps your process at perceptible priority. |
| Recycle | Cancel in-flight decodes and monitor leaks | Scope image requests to UI lifecycles so backgrounded scroll decodes don't inflate memory, and use LeakCanary and the Memory Profiler to catch backstack leaks. See Manage your app's memory. |