java.lang.OutOfMemoryError: bitmap size exceeds VM budget

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?


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.


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);
链接地址: http://www.djcxy.com/p/93102.html

上一篇: 我不断收到java.lang.outofmemory错误

下一篇: java.lang.OutOfMemoryError:位图大小超过VM预算