如何解决常见的内存不足的错误在Android模拟器? [英] How can I fix frequent Out Of Memory Errors on Android emulators?

查看:179
本文介绍了如何解决常见的内存不足的错误在Android模拟器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我测试一个移动应用程序,并一直在努力与应用程序的不断崩溃时我使用Android模拟器。我对物理Android设备没有问题,但模拟器每天死机好几次。该应用程序会崩溃相当一致,一旦我找到应用程序的工作流程的崩溃倾向的一部分。但是,正是在该应用程序将触发崩溃似乎因版本不同而不同。

I test a mobile app and have been struggling with constant crashes of the app when I use an Android emulator. I have no problem on physical Android devices, but emulators crash several times per day. The app will crash quite consistently once I find a crash-prone part of the app's "workflow". But exactly where in the app will trigger a crash seems to vary from version to version.

下面是崩溃报告

Android: 2.3.7
Model: Full Android on x86 Emulator

java.lang.OutOfMemoryError: bitmap size exceeds VM budget
at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:470)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:525)
at our.app.util.OurAppFileManager.getBrandingImageFromSD(OurAppFileManager.java:104)
at our.app.MainScreen.onResume(MainScreen.java:150)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
at android.app.Activity.performResume(Activity.java:3832)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2110)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2135)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1668)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)

这里是一个截图我的仿真器设置

我试图改变没有多少运气的RAM和VM堆和内部存储设置。事实上,该仿真器发射器将开始,如果我设置的RAM过高的抱怨。

I have tried changing the RAM and VM Heap and Internal Storage settings without much luck. In fact, the emulator launcher will start to complain if I set the RAM too high.

推荐答案

您无论是真正已用完堆空间,或堆足够支离破碎的Andr​​oid无法分配任何你正在请求。这将发生在生产设备,以及,所以这当作一个模拟器的问题是错误恕我直言。

You either truly have run out of heap space, or the heap is sufficiently fragmented that Android cannot allocate whatever you are requesting. This will happen on production devices as well, and so treating this as an emulator issue is a mistake IMHO.

我会做更多的测试与4.x的模拟器启动。一定程度上,这会给你更好的崩溃信息,包括如何分配的大失败。一定程度上,它会用垫时,要弄清楚,你的堆将会给你大大更好的结果。

I'd start by doing more testing with the 4.x emulator. Partly, that will give you better crash information, including how large of an allocation failed. Partly, it will give you substantially better results when using MAT to figure out where your heap is going.

有许许多多数不胜数的问题和答案在这里的StackOverflow关于的OutOfMemoryError 与位图的分配。你不妨浏览一番。他们将指向您在相同的基本方向:

There are umpteen zillion questions and answers here on StackOverflow regarding OutOfMemoryError with bitmap allocation. You may wish to browse through some. They will point you in the same basic directions:

  • 在安卓3.0+,使用 inBitmap BitmapOptions 您传递给 BitmapFactory ,以相对于分配新的内存重用现有的内存

  • On Android 3.0+, use inBitmap on the BitmapOptions that you pass to BitmapFactory, to reuse existing memory as opposed to allocating new memory

循环()位图的对象,当你与他们做

recycle() your Bitmap objects when you are done with them

通常要小心你的内存分配,由于Android的垃圾回收器的不密实,所以最终你将无法再次分配的内存大块的

Be generally careful about your memory allocations, as Android's garbage collector is non-compacting, so eventually you will be incapable of allocating large blocks of memory again

使用MAT看到,如果你正在泄漏内存的地方,正在助长你的问题

Use MAT to see if you are leaking memory somewhere that is contributing to your problem

等等。

这篇关于如何解决常见的内存不足的错误在Android模拟器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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