Out of memory error on android emulator, but not on device

26,411

Solution 1

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);
}

Solution 2

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.

Solution 3

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

Solution 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

Share:
26,411
piojo
Author by

piojo

Updated on July 09, 2022

Comments

  • piojo
    piojo almost 2 years

    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?

  • piojo
    piojo almost 13 years
    its on 24. isn't it the same on the device?
  • piojo
    piojo almost 13 years
    well, I added it to 32 and now it works fine. but does all devices have this amount of memory?
  • piojo
    piojo almost 13 years
    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
  • ol_v_er
    ol_v_er almost 13 years
    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?
  • Avram Score
    Avram Score almost 13 years
    Some sample max heap sizes: G1 = 16 Mb Droid = 24 Mb Nexus One = 32 Mb Xoom = 48 Mb GalaxyTab = 64 Mb.