2

I have this function that loads a big bitmap from SD and rotates it.

Yet after the second or third rotating I get a bitmap size exceeds VM budget error.

Any ideas why? I do recycle the old bitmap, don't it?

public void next(String s, int d)
{

if ( mBitmap!=null ) { mBitmap.recycle(); }

deg = deg + d;
mBitmap = BitmapFactory.decodeFile(s);

Matrix matrix = new Matrix();
matrix.postRotate(deg);
mBitmap = Bitmap.createBitmap(mBitmap, 0, 0, mBitmap.getWidth() , mBitmap.getHeight(), matrix, true);

Thanks!

Roger Travis
  • 8,402
  • 18
  • 67
  • 94
  • This will help you: http://stackoverflow.com/questions/3823799/android-bitmap-recycle-how-does-it-work – sromku Aug 25 '12 at 20:44

2 Answers2

2

Its not uncommon for outof memory errors when you dont use bitmaps properly.

Bitmaps take up a lot of memory, especially for rich images like photographs. For example, the camera on the Galaxy Nexus takes photos up to 2592x1936 pixels (5 megapixels). If the bitmap configuration used is ARGB_8888 (the default from the Android 2.3 onward) then loading this image into memory takes about 19MB of memory (2592*1936*4 bytes), immediately exhausting the per-app limit on some devices.

There is a great android guide on how to use Bitmaps efficiently.

Following the guide, you should be able to reduce your memory consumption dramatically with out losing any visible quality, avoiding unecessary crashes.

IAmGroot
  • 13,760
  • 18
  • 84
  • 154
1

code seems fine.

however , this exception also depends on the size of the bitmap (resolution and bitmap format) , and other memory consuming objects.

android developer
  • 114,585
  • 152
  • 739
  • 1,270