Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 668
piojo Avatar asked Sep 15 '11 08:09

piojo


People also ask

How do I give my Android Emulator more memory?

Go to Tools->Android->AVD Manager , there's something like pencil to edit your AVD click on that, then in the pop-up window click Show Advanced Settings and there you can change the RAM size.


2 Answers

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);
}
like image 95
ol_v_er Avatar answered Sep 30 '22 11:09

ol_v_er


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.

like image 35
Avram Score Avatar answered Sep 30 '22 12:09

Avram Score