20

On the Android Emulator, when I exit my app and run it again immediately, I get

OutOfMemoryError: bitmap size exceeds VM budget.

But on the device itself, this does not happen. Why?

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
piojo
  • 1,919
  • 4
  • 24
  • 40
  • I think you are using static Bitmap array, which you not assigning to null after leaving activity. set that to null on closing activity. – Balaji Khadake Sep 15 '11 at 08:21

6 Answers6

17

On a emulator the default max heap size is around 13MB.

On a device, it depends of the phone and of the android version. On my Motorola Droid, the max heap size is around 21-22MB and on my HTC Desire it's around 32MB.

That's why you have a crash on the emulator and not on your device.

If you want to monitor the heap size of your application you can call a similar method:

protected void displayMemoryUsage(String message) {
    int usedKBytes = (int) (Debug.getNativeHeapAllocatedSize() / 1024L);
    String usedMegsString = String.format("%s - usedMemory = Memory Used: %d KB", message, usedKBytes);
    Log.d(TAG, usedMegsString);
}
ol_v_er
  • 27,094
  • 6
  • 48
  • 61
  • 1
    found out a big problem in my program, it uses way too much memory. I load a bitmap(478 KB) but it takes ~5000 KB to load it – piojo Sep 15 '11 at 09:19
  • It seems a bit too much memory for a single image. What is the resolution of this image and it's format? If you do not need the full resolution image in your app, did you consider reducing it's resolution or adding a inSampleSize in your BitmapFactory? – ol_v_er Sep 15 '11 at 11:52
13

Increase the AVD RAM and the max VM application heap size in VM options.

To do that, go to

Window-->AVD Manager-->Virtual Devices-->Edit.

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
Avram Score
  • 3,927
  • 2
  • 17
  • 12
5

You need to increase heap size for the emulator - it worked for me i increased it from 16 M to 32 M

Atul Darne
  • 746
  • 7
  • 14
4

Here is a lazy for how to find the options to manipulate heapsize for emulator from Andriod studio 1.2.0

  1. Menu Tools->Android->AVD Manager
  2. edit the virtual device of choice
  3. click advanced settings and scroll down

Change VM heap in android studio

Aksel Willgert
  • 11,367
  • 5
  • 53
  • 74
1

Probably it is because you're device has more memory than your emulator. This SO question shows you how to increase the size on your emulator.

Additionally you could increase the Java VM Heap size.

Community
  • 1
  • 1
  • Then try to increase the VM heap size: http://viralpatel.net/blogs/2009/01/jvm-java-increase-heap-size-setting-heap-size-jvm-heap.html –  Sep 15 '11 at 08:15
0

Increase the size of memory allocated...