OutOfMemoryError: bitmap size exceeds VM budget: - Android

Possible duplicate:
Android: Strange memory issue when loading image into Bitmap object

I download images from Url and display them. At boot time, it gives out of memory error : bitmap size exceeds VM budget . I am using drawable. Code below:

 HttpClient httpclient= new DefaultHttpClient(); HttpResponse response=(HttpResponse)httpclient.execute(httpRequest); HttpEntity entity= response.getEntity(); BufferedHttpEntity bufHttpEntity=new BufferedHttpEntity(entity); InputStream instream = bufHttpEntity.getContent(); Bitmap bm = BitmapFactory.decodeStream(instream); Bitmap useThisBitmap = Bitmap.createScaledBitmap(bm,bm.getWidth(),bm.getHeight(), true); bm.recycle(); BitmapDrawable bt= new BitmapDrawable(useThisBitmap); System.gc(); 

Here is the error: 05-28 14:55:47.251: ERROR/AndroidRuntime(4188): java.lang.OutOfMemoryError: bitmap size exceeds VM budget

+52
android out-of-memory bitmap
May 28 '10 at 9:49 a.m.
source share
7 answers

Use decodeStream(is, outPadding, opts) with

 BitmapFactory.Options opts=new BitmapFactory.Options(); opts.inDither=false; //Disable Dithering mode opts.inPurgeable=true; //Tell to gc that whether it needs free memory, the Bitmap can be cleared opts.inInputShareable=true; //Which kind of reference will be used to recover the Bitmap data after being clear, when it will be used in the future opts.inTempStorage=new byte[32 * 1024]; 
+31
May 04 '11 at 4:57
source share

You can check the size of the image, and then reduce it using the appropriate ratio.

See this question: Processing large raster images

+5
May 28 '10 at 11:57
source share

This problem seems to have been reported several times, here and here , for example ... sorry Shalini, but if this is the same problem, it seems that there is no solution at all ...

The only advice of Romain Guy is to use less memory ...

So, good luck, think of your things differently ...

+2
May 28 '10 at 10:01
source share

Finally, after reconfiguring the image, as suggested above, you can call bitmap_file.recycle () .

+1
May 28 '10 at 12:48
source share

The fact is that there is an error on some versions of Android, especially in version 2.1 with errors all the time with such problems.

I released an application in which I paid a lot of attention to the use of resources. I even deleted many of the bitmaps that I used, and now they are created on the fly using graphic primitives. I also process bitmap images when not in use. And, of course, I checked that I have no memory leaks in my application: the memory used is NOT growing without control, it is constantly kept within reasonable limits.

Although I make a lot of efforts to avoid this problem, I continue to receive many annoying exceptions, such as those from devices 2.1 and 2.1-update1. I use critical analysis to report crashes, and I saw that this happens even when the application uses only 4 megabytes of RAM, which is four times less than the 16 MB heap size that every Android device for an application should have, - and the fact is that most devices today have heap sizes over 16 M -.

All my bitmaps are 800x480 pixels in size, which is the worst case scenario since ARGB_8888 may not take up more than 1.5 MB each, but it crashes trying to load it when occupying just 4 megabytes, so there should be at least another 12 MB free. And most of my bitmaps load like ARGB_4444, which takes up half the memory, I only use ARGB_8888 when the bitmaps look really bad with 4444.

So, for me it is pretty clear that on these versions of Android there is something that does not work fine. 99'9% of these failures come from 2.1 and 2.1 updates, and the rest can be explained by other punctual reasons.

0
Jul 01 '12 at 1:18
source share

I tried a lot of things, this is what works.

 BitmapFactory.Options opts=new BitmapFactory.Options(); opts.inDither=false; //Disable Dithering mode opts.inPurgeable=true; opts.inScale=8; ///after you use your images System.gc(); 
0
Aug 16 '12 at 17:56
source share

This is a practical answer that I tried to avoid this problem at runtime. And that also solved my problem.

 Runtime.getRuntime().gc(); 

Calling Garbage Collector is a good idea.

-2
Dec 02 2018-11-12T00:
source share



All Articles