0

Im determining the size that a bitmap will take in memory using the following method:

bitmapOptions.inJustDecodeBounds = true;
BitmapFactory.decodeFile(imagePath, bitmapOptions);
long bitmapSizeInMB = (bitmapOptions.outWidth *     bitmapOptions.outHeight * 4) / 1048576L);
bitmapOptions.inJustDecodeBounds = false;

And the result, for example, is 5MB

But what happens is, the moment I decode the bitmap using

bitmap = BitmapFactory.decodeFile(imagePath, bitmapOptions);

and set it to an imageview, the GC system message in Logcat says RAM usage has increased by 20 MB, not 5.

So my question is, by doing this bitmap size check operation, do I increase the RAM usage?

Kaloyan Roussev
  • 14,515
  • 21
  • 98
  • 180

1 Answers1

0

I think the ImageView allocates ram for the image based on the bitmaps size.Regardless if the bitmap has been set or not, since you supplied bitmapOptions which comes with the dimensions.

cgew85
  • 427
  • 3
  • 9
  • okay but according to this measuring that I do, memory allocated should be 5, not 20 MB? – Kaloyan Roussev Dec 17 '14 at 12:05
  • You can find it out :) try this: http://stackoverflow.com/questions/14366410/how-to-get-the-in-memory-size-of-an-object-in-android-or-performance-benchmarks – cgew85 Dec 17 '14 at 12:10