1

I use the camera in my android app and I hold my phone in portrait mode (the cameraView is in Landscape, that's the first thing strange) and when I turn my phone to have it in landscape mode, I get errors.

VM won't let us allocate ... bytes

The error line showed is

setContentView(R.layout.gameactivity);

This post is interesting Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget Yet I use no bitmaps in my activity so I don't know why I get erros about Bitmaps

02-01 10:07:30.301: E/AndroidRuntime(5715): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
02-01 10:07:30.301: E/AndroidRuntime(5715):     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
02-01 10:07:30.301: E/AndroidRuntime(5715):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460)
02-01 10:07:30.301: E/AndroidRuntime(5715):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
02-01 10:07:30.301: E/AndroidRuntime(5715):     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
02-01 10:07:30.301: E/AndroidRuntime(5715):     at android.content.res.Resources.loadDrawable(Resources.java:1709)
02-01 10:07:30.301: E/AndroidRuntime(5715):     at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
02-01 10:07:30.301: E/AndroidRuntime(5715):     at android.widget.ImageView.<init>(ImageView.java:118)
02-01 10:07:30.301: E/AndroidRuntime(5715):     at android.widget.ImageView.<init>(ImageView.java:108)
02-01 10:07:30.301: E/AndroidRuntime(5715):     ... 27 more
Community
  • 1
  • 1
morg
  • 1,173
  • 4
  • 18
  • 36

1 Answers1

1

You got a memory leak.
When the device changes the layout the Activity will be created again. Most likely you got for example some huge static variables etc. that won't get released.
Maybe adding "onConfigChanged:orientation" Tag to your Activity in Manifest helps you to prevent the memory leak, but it's not a good solution for every case.
There are also several sites that show you how to find the memory leaks, like this

Thommy
  • 5,070
  • 2
  • 28
  • 51
  • Thanks for the onConfigChanged it helped but now, when I turned my screen it works find, when I take the picture the program collapses again... – morg Feb 01 '13 at 12:16
  • As I said, it won't make the leak go away, so check you code for memory leaks. Since you take Pictures i guess you have too large Bitmaps or you aren't recycling them. On Stackoverflow you can find many Questions about Bitmaps and OOM in Android. – Thommy Feb 01 '13 at 12:39
  • I have those possible leaks using eclipse memory analyzer http://stackoverflow.com/questions/14646029/android-detecting-leaks-with-eclipse-memory-analyzer if you have time to get a look at it I don't know if from these results we can say whether or not I have leaks, I don't know most of the possible leak classes.. – morg Feb 01 '13 at 13:42
  • + Even if I comment my Bitmap objects and dont have anymore, I still have bitmap errors... – morg Feb 01 '13 at 14:42
  • Bitmaps can also be Background-Images added in XML – Thommy Feb 04 '13 at 07:52