Need some help for understanding the recycle() method of the class Bitmap.
If I have a Bitmap[] named "bmp" for example whats the difference between doing
Bitmap[i].recycle()
And
Bitmap[i]=null;
Whats the best option? Should I call both?
Thanks
If you're displaying large amounts of bitmap data in your app, you're likely to run into OutOfMemoryError errors. The recycle() method allows an app to reclaim memory as soon as possible. Caution: You should use recycle() only when you are sure that the bitmap is no longer being used.
A bitmap is simply a rectangle of pixels. Each pixel can be set to a given color but exactly what color depends on the type of the pixel. The first two parameters give the width and the height in pixels. The third parameter specifies the type of pixel you want to use.
You can use eraseColor on bitmap to set its color to Transparent. It will useable again without recreating it.
You can do a check when you want to return the BitMap look to see if the ArrayList of Paths is bigger than 0 and return the BitMap if so, or else return null.
According to this question, bitmap data is stored in native memory rather than in the Dalvik heap. You should call recycle()
to free the memory the bitmap is stored in once you are finished with it. It's good practice to set it to null afterwards, although this is somewhat redundant.
See also the api: http://developer.android.com/reference/android/graphics/Bitmap.html#recycle()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With