I have been monitoring the memory consumption in my Android application and noticed an interesting phenomenon. When loading a bitmap (a PNG file, 380x10640), I observed the memory amount available after executing the code of loading the bitmap decreased by 15 MB on some devices (for example, Modecom FreeTab 9004, API 17) and by as much as 60 MB on the other (namely, Nexus4 API 25). Could anyone explain me the reason why this is happening?
I used Runtime.getRuntime().freeMemory()
to monitor the heap, and the following commands to load the bitmap.
Resources r = getResources();
private Bitmap imageOne;
// ...
imageOne = BitmapFactory.decodeResource(r, R.drawable.bitmap_1);
Difference in memory consumption should be due to different device-default Bitmap Config.
For example, if the default is
RGBA_F16
, then each pixel takes 8 bytes,ARGB_8888
- 4 bytes. So if you calculate:As for 60 mb instead of 32 - the image might be cached, buffered, or you accidentaly load it twice.
You can manually load image. This way you can select the Config for it.
UPDATE1: Or 60 mb vs 15 mb might be caused by image pre-scaling for different DPI