Your code is going about doing nothing... first you create a ByteArrayOutputStream
with the size equal to image width*height, which is wrong no matter how you look at it: if you were writing raw bitmap data it should be 4*width*height, but you are writing a compressed JPG, whose resultant size would not correlate with image width/height. Then you close and set the stream to null so nothing is accomplished. Then you call loadedImage.recycle()
so loadedImage cannot ever be used again, but you put it in a Map with a clear intent to use it later...
Try removing loadedImage.recycle() and see if it helps, and read Android doc on Bitmap.recycle():
To answer some of your other questions in the comments:
so if that clearing the Bitmap, why the images were there then?
Per Android documenation:
This will not free the pixel data synchronously; it simply allows it to be garbage collected if there are no other references.
Basically it means if you called recycle()
, subsequent behavior is undefined as far API is concerned. If memory serves, the behavior is different pre-Andorid 4.0 and post(including) Android 4.0, since they've moved the byte[] buffer backing a Bitmap from native memory space into VM managed memory space.
GC_FOR_ALLOC messages still there.
Because you are still creating lots of large objects, it's normal. If you want to reduce it, remove the ByteArrayOutputStream
and associated code.