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

后端 未结 6 2343
渐次进展
渐次进展 2020-12-05 18:42

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

OutOfMemoryError: bitmap size exceeds VM budget.

But on th

相关标签:
6条回答
  • 2020-12-05 19:17

    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

    0 讨论(0)
  • 2020-12-05 19:20

    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);
    }
    
    0 讨论(0)
  • 2020-12-05 19:21

    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.

    0 讨论(0)
  • 2020-12-05 19:30

    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.

    0 讨论(0)
  • 2020-12-05 19:32

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

    0 讨论(0)
  • 2020-12-05 19:41

    Increase the size of memory allocated...

    0 讨论(0)
提交回复
热议问题