出于对Android模拟器内存​​错误,但不是在装置 [英] Out of memory error on android emulator, but not on device

查看:212
本文介绍了出于对Android模拟器内存​​错误,但不是在装置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android模拟器,当我离开我的应用程序,并立即再次运行它,我得到

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?

推荐答案

在一个仿真器的默认最大堆大小约为13MB。

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

在设备上,这取决于Android版手机和。在我的摩托罗拉Droid,最大堆大小约为21-22MB和我的HTC Desire是32MB左右。

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

这篇关于出于对Android模拟器内存​​错误,但不是在装置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆