tyczj
tyczj

Reputation: 73753

Safe to recycle bitmap?

I have a bitmap and I am creating a byte array from it like following

BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;

Bitmap b = BitmapFactory.decodeFile(imageUri,o2);
b.compress(Bitmap.CompressFormat.JPEG,100,stream);
b.recycle(); //safe to do here?

Is it safe to recycle the bitmap at this point or do I have to wait until I create the type array to recycle.

byte[] image = stream.toByteArray();
b.recycle(); //or do I need to do it here?

Upvotes: 0

Views: 223

Answers (1)

Mohsin
Mohsin

Reputation: 86

After you call b.compress(), the data for the bitmap should already be written to the OutputStream, so you don't need the Bitmap any longer and it is safe to recycle it after your call to compress.

Upvotes: 2

Related Questions