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?
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.
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);
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With