views:

1304

answers:

4

Hi! i am downloading images from Url and displaying them. At download time it is giving out of memory error : bitmap size exceeds VM budget. I am using drawable. Code is 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

A: 

This issue seems to have been reported several times, here and here for instance... sorry Shalini but if it's the same issue, it seems that there is no solution at all...

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

So, good luck to think your stuff differently...

Sephy
There is a solution: use less memory than the maximum allowed. I know this is a frustrating answer but phones do not have "unlimited" amount of RAM like desktop machines. You have to be careful.
Romain Guy
Didn't know you were coming on stack ;)As I said, your recommandation was to use less memory...What would you advise to do for that? reduce the size of the picture?
Sephy
+1  A: 

If the image is really big this solution should help http://stackoverflow.com/questions/477572/android-strange-out-of-memory-issue/823966#823966

Fedor
+1  A: 

You could check the image size and then downsample it by appropriate factor.

See this question: Handling large Bitmaps

Samuh
+1  A: 

Finally, after resample the image as suggested above, you may call bitmap_file.recycle().

Rorist