1

I use a jpeg in my Android App that takes up 1.6 MB on disk (on OSX). I noticed garbage collector warnings in the app logs, and took a heap dump in Android Studio. Out of a retained heap size of 36.5 MB, my home page fragment (this is the one with the jpeg) is taking up 36 MB.

I loaded the heap dump in Memory Analyzer Tool (MAT) and see a android.graphics.Bitmap taking up 36 MB of space in the heap. It's attribute view doesn't show the file name, but the dimensions match the 1.6 MB jpeg's dimensions.

MAT General View

MAT Attribute View

How would an image that takes up less than 2 MB on disk take up 36 MB on an Android app's heap?

Thanks

user1114
  • 1,071
  • 2
  • 15
  • 33

2 Answers2

1

JPEG is a compressed image format. To render it, Android needs to decompress it.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 2
    ...and as CommonWare says, an image that is 4000x2250 at 4 bytes per pixel is 36MB. Makes sense to me. – spartygw May 26 '20 at 18:18
0

Well as @CommonsWare pointed out, bitmap is being displayed not the compressed format, which in your case is JPEG.

But as to how to solve this evident problem; bitmap down-sampling, bitmap configurations, and resizing are valid options to decrease your bitmap size.

Nonetheless, managing your memory allocation is always a good idea. Specially something like Managing Bitmap Memory and Caching Bitmaps.

And that usually boils down to

1- Version(s) of Android you are targeting

2- Memory vs. Disk cache
0xA
  • 1,519
  • 1
  • 9
  • 23