Thursday, September 22, 2011

[android-developers] Re: How to resolve outOfMemoryError - Bitmap size exceeds VM budget

I assume you have your images shown in an ImageView.

For each of your activities that shows the image in an ImageView:

In the onStart():
  ...
  myBitmap = loadBitmap();
  imageView.setImageBitmap(myBitmap);
  ...

In the onStop():
  ...
  imageView.setImageDrawable(null); // disassociates the bitmap from the imageView and it won't access it again.
  myBitmap.recycle();
  myBitmap = null;
  ...

In the loadBitmap():
  Here it is up to you how to load the bitmap, since I don't know where you get your images from.


(If you  don't show the images in an ImageView, you'd have to find another way to disassociate the bitmap from that other View/control/whatever)


--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment