I'm working with some Classes that holds a reference to a Bitmap
like the following:
class Picture {
private String localPath;
private Bitmap bitmap;
// setters and getters....
}
Then on certain fragments I use picture.setBitmap(BitmapUtils.decodeBitmap(picture.getLocalPath, size));
to get a reference and afterwards set it to an ImageView
. But I'm never doing bitmap.recycle()
or bitmap = null;
explicitly.
I'm not really sure how does bitmaps works internally and why the GC wouldn't collect them in some situations, so I want to know if what am I doing might cause a memory leak, and how can I prevent this, given the fact that bitmaps reference are only stored on an object as a holder
Edit: since it seems to be some kind of confusion on what am I doing with the Bitmap
, I'll explain some more. The business model in the information system defines a couple of entities that have images as attributes (for example, a profile, which the user have a profile name, and a profile picture).
It is indeed true that in cases like that, you normally would keep the picture path as the attribute instead of the picture itself. But since I'm taking several pictures from the Android
camera, I'm saving it to a list to perform batch operations. You can see it as if the entity works as a holder for the picture itself, since you need a reference to each picture to perform batch operations on them.