0

In my app I am fetching 4-5 bitmaps from url and I use them like a gallery.

if i switch images more than 6-10 times I am getting this error:

09-01 12:08:45.217: E/AndroidRuntime(350): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
09-01 12:08:45.217: E/AndroidRuntime(350):  at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
09-01 12:08:45.217: E/AndroidRuntime(350):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:459)
09-01 12:08:45.217: E/AndroidRuntime(350):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:515)

This is my code:

try {
                            bitmapResult = BitmapFactory.decodeStream((InputStream)new URL(url[newPage+1]).getContent());
                          } catch (MalformedURLException e) {
                          e.printStackTrace();
                        } catch (IOException e) {
                          e.printStackTrace();
                        }

                        v.setImageBitmap(bitmapResult);

My question os this:

Will this happen only in emulator?

Morevoer, and more important. Will it me more efficient if using drawable insted? In that case I will convert my bitmap to drawable with code below and I will setImageresource. Do I have to "release" anything?

Drawable d = new BitmapDrawable(getResources(),bitmapResult);
ghostrider
  • 5,131
  • 14
  • 72
  • 120
  • 1
    a `BitmapDrawable` is just wrapping a `Bitmap` so it uses the same amount of memory. – zapl Sep 01 '12 at 13:03

1 Answers1

0

when you are loading bitmaps from you internal storage - recycle the bitmap afterwards!

there are many threads around here with the problem VM out of memory...

Lukas Olsen
  • 5,294
  • 7
  • 22
  • 28