0

I have created one game which uses images and my game is in portrait and landscape mode. I have 2 different layout for that When i switch from 1 orientation to other, after doing this 5 6 times, it gives force close error Error is like :

Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget

Anyone know the solution? is there any way to clean up all images in switching orientation ? thanks in advance

djk
  • 3,671
  • 9
  • 31
  • 40
  • 3
    There are many questions has been asked earlier. Check this http://stackoverflow.com/search?q=OutOfMemoryError%3A+bitmap+size+exceeds+VM+budget – Vikas Patidar Feb 04 '11 at 05:24
  • djk also this post has link to such issues http://stackoverflow.com/questions/4656961/how-to-fix-error-in-bitmap-size-exceeds-vm-budget/4657285#4657285 & yeah +1 @Creative MITian – 100rabh Feb 04 '11 at 08:40

2 Answers2

1

i got the solution from this link http://android-developers.blogspot.com/2009/01/avoiding-memory-leaks.html

i have a lots of images are setting in imageview every time orientation changes. i just make backgorund image static and problem solved

private static Drawable BackgroundP;
private static Drawable BackgroundL;

if (conf.orientation == Configuration.ORIENTATION_LANDSCAPE){
   if(BackgroundL == null){
      BackgroundL = getResources().getDrawable(R.drawable.backgroundland);
   }
} else {
   if(BackgroundP == null){
      BackgroundP = getResources().getDrawable(R.drawable.backgroundport);
   }
}

this will only set drawble one time.

hope this will help anyone.

djk
  • 3,671
  • 9
  • 31
  • 40
1

@djk Oh yeah, it will load drawable one time, but will also create memory leak. This article explains why: http://android-developers.blogspot.com/2009/01/avoiding-memory-leaks.html