简体   繁体   中英

Intel HAXM and Out Of Memory error when running Android application

We experience Out Of Memory Error when running our application on Intel HAXM emulator. At the same time application is stable when we run it in usual android ARM Emulator. The error log is:

12-03 12:13:20.258: ERROR/AndroidRuntime(3048): FATAL EXCEPTION: main
        java.lang.RuntimeException: Unable to start activity ComponentInfo{coza.sintez.xplat/coza.sintez.xplat.activity.fields.NumberFieldActivity}: android.view.InflateException: Binary XML file line #4: Error inflating class <unknown>
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
        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)
        Caused by: android.view.InflateException: Binary XML file line #4: Error inflating class <unknown>
        at android.view.LayoutInflater.createView(LayoutInflater.java:518)
        at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
        at android.view.LayoutInflater.parseInclude(LayoutInflater.java:682)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:619)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
        at android.app.Activity.setContentView(Activity.java:1657)
        at coza.sintez.xplat.activity.fields.NumberFieldActivity.onCreate(NumberFieldActivity.java:51)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
        ... 11 more
        Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.constructNative(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
        at android.view.LayoutInflater.createView(LayoutInflater.java:505)
        ... 26 more
        Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
        at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
        at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460)
        at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
        at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
        at android.content.res.Resources.loadDrawable(Resources.java:1709)
        at android.content.res.Resources.getDrawable(Resources.java:581)
        at android.graphics.drawable.InsetDrawable.inflate(InsetDrawable.java:103)
        at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
        at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:172)
        at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
        at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
        at android.content.res.Resources.loadDrawable(Resources.java:1694)
        at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
        at android.view.View.<init>(View.java:1951)
        at android.widget.TextView.<init>(TextView.java:350)
        at android.widget.Button.<init>(Button.java:108)
        at android.widget.Button.<init>(Button.java:104)
        ... 29 more
12-03 12:13:20.318: WARN/ActivityManager(851): Force finishing activity coza.sintez.xplat/.activity.fields.NumberFieldActivity 

All activities are optimized and do not use large bitmaps. DDMS memory profiler do not show any memory leaks as well.

Also we noticed that if we run application at the first time, it can perform some task(for example navigate to some activity). But if we completely re-install application and run again, it fails doing the same task. Seems like Intel Emulator is not freeing up memory correctly. Has anybody experienced the same?

by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget at

clearly bitmap size exceed VM budget and when you second time run your app still bitmap factory hold that image in factory which is actually in VM budget.

remove bitmap onDestroy Activity

In your code error java.lang.OutOfMemoryError: Bitmap Size Exceeds VM Budget is appeared

check this thread for more solution.

Don't be surprised by having Out of memory error in AVD and not with the other.

Each AVD has his own configuration for maximum Heap memory, and the reason why you are hitting it with Intel emulator is just that the default maximum heap memory made available for your app is smaller than the one provided by ARM emulator.

You can check the heap memory available to your app using:

Log.d(TAG,"Heap size: " + Runtime.getRuntime().maxMemory());

Although you can control the heap size in the emulator and make it run in both, you can't do it for the user device.

So, if you are trageting devices with smaller heap size, you need to review your code and ensure that it fits in that amount of memory. Otherwise, you can specify the minimum amount of heap required for your application in AndroidManifest.xml and it will only shows suitable devices.

Regards.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM