Skip to content Skip to sidebar Skip to footer

Why Does My 160kb App Background Become 49 Mb At Run Time?

I decided to investigate my app's memory usage and I looked at Android Studio's Memory Monitor and my memory usage was around 68 MB. It looks too high to me. I opened memory alloc

Solution 1:

If the device has a resolution of 1440x2560, why would my background get converted to 2625x4669?

You put the image in res/drawable/. This is not a good choice, as that is a synonym for res/drawable-mdpi/. Hence, Android is resampling your image, thinking that you were aiming for -mdpi devices (~160dpi), so the image is about the same physical size on the Nexus 6 (3.5x the density).

Whether res/drawable-nodpi/ or res/drawable-anydpi/ is the right choice depends a bit on your alternative versions of this resource, though either will probably work.

how come a 160 KB file would end up being 49 MB?

The image takes up 160KB on disk. The memory footprint is the decoded image. That will be the image resolution (post-resampling) times 4 bytes/pixel for ARGB_8888 images. 2625x4669x4 ~= 49MB.

Solution 2:

The default and highest quality configuration for a Bitmap is ARGB_8888, which will use 4 bytes per pixel. Since your image is being scaled to 2625*4669, that's:

2625*4669*4bytes = 49024500bytes

http://developer.android.com/reference/android/graphics/Bitmap.Config.html

Solution 3:

I'm not sure about the resolution differences, but the difference between the used memory and the size of the file is because an image in the JPG format (as many other formats) is compressed (see the wiki for how). When you then load it into memory, it is no longer compressed, as it's used to draw every single pixel on the screen.

Post a Comment for "Why Does My 160kb App Background Become 49 Mb At Run Time?"