0

Possible Duplicate:
Android: Strange out of memory issue while loading an image to a Bitmap object

I am getting following error when I load bitmap on imageview in AsyncTask:

Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget

Is there any help?

Community
  • 1
  • 1
nirav
  • 411
  • 2
  • 8
  • 18
  • 1
    My guess is that you need more physical memory, a larger allocation for your JVM, or a smaller image. – duffymo Jul 15 '11 at 09:31
  • 2
    @nirav: Please look at the "Related" links (on the right of this page) – Mat Jul 15 '11 at 09:34

2 Answers2

2

It could be helpful to watch the memory management session of this year's google i/o: Memory management for Android Apps Here, Patrick Dubroy explains some cases which can lead to memory leaks (particularly keeping a long lived reference to the application's context via static members). He also talks about the garbage collector.

sladstaetter
  • 453
  • 4
  • 11
0

I had the same problem. I solved the problem resampling the bitmap to lower resolution, and then using imageView.clearAnimation(); before to load the new bitmap on the imageView. Vote me if this helps you too. Regards. Note: in the following sample, data contains the new image data for the camera image picker and imageView is our ImageView.

    Bitmap photo=null;
    imageView.clearAnimation();     
    Uri photoUri =  data.getData(); 
    InputStream imageStream = null;
    try {
    imageStream = getContentResolver().openInputStream(photoUri);
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    }

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPurgeable = true;
    options.inSampleSize=2;
    Rect outPadding= new Rect(-1, -1, -1, -1);
    photo = BitmapFactory.decodeStream(imageStream, outPadding, options);
    imageView.setImageBitmap(photo);
Gaucho
  • 1,328
  • 1
  • 17
  • 32