码迷,mamicode.com
首页 > 其他好文 > 详细

关于解决VM heap的问题

时间:2014-09-07 18:36:05      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:android

<p>
今天弄个简单的图片显示程序</p>
LinearLayout linearLayout =(LinearLayout)this.findViewById(R.id.LinearLayout1);
        for(int i=0;i<imagePath.length;i++)
        {
        	img[i]=new ImageView(this);
        	img[i].setImageResource(imagePath[i]);
        	img[i].setPadding(5, 5, 5, 5);
        	LayoutParams layoutParams=new LayoutParams(253,148);
        	img[i].setLayoutParams(layoutParams);
        	linearLayout.addView(img[i]);
        }

在物理机运行正常,但是在模拟器运行出现下面的问题:

09-07 05:58:48.972: D/dalvikvm(1981): GC_FOR_ALLOC freed 48K, 4% free 2739K/2844K, paused 24ms, total 25ms
09-07 05:58:48.972: I/dalvikvm-heap(1981): Grow heap (frag case) to 6.412MB for 3864408-byte allocation
09-07 05:58:48.992: D/dalvikvm(1981): GC_FOR_ALLOC freed 2K, 2% free 6510K/6620K, paused 18ms, total 18ms
09-07 05:58:49.082: D/dalvikvm(1981): GC_FOR_ALLOC freed 10K, 2% free 6514K/6620K, paused 2ms, total 2ms
09-07 05:58:49.082: I/dalvikvm-heap(1981): Grow heap (frag case) to 10.098MB for 3864408-byte allocation
09-07 05:58:49.122: D/dalvikvm(1981): GC_FOR_ALLOC freed <1K, 2% free 10288K/10396K, paused 23ms, total 23ms
09-07 05:58:49.412: D/dalvikvm(1981): GC_FOR_ALLOC freed <1K, 2% free 10289K/10396K, paused 2ms, total 3ms
09-07 05:58:49.412: I/dalvikvm-heap(1981): Grow heap (frag case) to 13.785MB for 3864408-byte allocation
09-07 05:58:49.452: D/dalvikvm(1981): GC_FOR_ALLOC freed <1K, 1% free 14063K/14172K, paused 27ms, total 28ms
09-07 05:58:49.722: D/dalvikvm(1981): GC_FOR_ALLOC freed <1K, 1% free 14064K/14172K, paused 3ms, total 3ms
09-07 05:58:49.722: I/dalvikvm-heap(1981): Forcing collection of SoftReferences for 3864408-byte allocation
09-07 05:58:49.732: D/dalvikvm(1981): GC_BEFORE_OOM freed 9K, 1% free 14055K/14172K, paused 4ms, total 4ms
09-07 05:58:49.732: E/dalvikvm-heap(1981): Out of memory on a 3864408-byte allocation.
09-07 05:58:49.732: I/dalvikvm(1981): "main" prio=5 tid=1 RUNNABLE
09-07 05:58:49.732: I/dalvikvm(1981):   | group="main" sCount=0 dsCount=0 obj=0xb3d20bd8 self=0xb8e4d4c0
09-07 05:58:49.732: I/dalvikvm(1981):   | sysTid=1981 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=-1216815008
09-07 05:58:49.732: I/dalvikvm(1981):   | state=R schedstat=( 0 0 0 ) utm=18 stm=1 core=0
09-07 05:58:49.732: I/dalvikvm(1981):   at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
09-07 05:58:49.732: I/dalvikvm(1981):   at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:587)
09-07 05:58:49.732: I/dalvikvm(1981):   at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:422)
09-07 05:58:49.732: I/dalvikvm(1981):   at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840)
09-07 05:58:49.732: I/dalvikvm(1981):   at android.content.res.Resources.loadDrawable(Resources.java:2110)
09-07 05:58:49.732: I/dalvikvm(1981):   at android.content.res.Resources.getDrawable(Resources.java:700)
09-07 05:58:49.732: I/dalvikvm(1981):   at android.widget.ImageView.resolveUri(ImageView.java:638)
09-07 05:58:49.732: I/dalvikvm(1981):   at android.widget.ImageView.setImageResource(ImageView.java:367)
09-07 05:58:49.732: I/dalvikvm(1981):   at com.jwy.linearlayout.MainActivity.onCreate(MainActivity.java:24)
09-07 05:58:49.732: I/dalvikvm(1981):   at android.app.Activity.performCreate(Activity.java:5231)
09-07 05:58:49.732: I/dalvikvm(1981):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-07 05:58:49.732: I/dalvikvm(1981):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
09-07 05:58:49.732: I/dalvikvm(1981):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
09-07 05:58:49.732: I/dalvikvm(1981):   at android.app.ActivityThread.access$800(ActivityThread.java:135)
09-07 05:58:49.732: I/dalvikvm(1981):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
09-07 05:58:49.752: I/dalvikvm(1981):   at android.os.Handler.dispatchMessage(Handler.java:102)
09-07 05:58:49.752: I/dalvikvm(1981):   at android.os.Looper.loop(Looper.java:136)
09-07 05:58:49.752: I/dalvikvm(1981):   at android.app.ActivityThread.main(ActivityThread.java:5017)
09-07 05:58:49.752: I/dalvikvm(1981):   at java.lang.reflect.Method.invokeNative(Native Method)
09-07 05:58:49.752: I/dalvikvm(1981):   at java.lang.reflect.Method.invoke(Method.java:515)
09-07 05:58:49.752: I/dalvikvm(1981):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
09-07 05:58:49.752: I/dalvikvm(1981):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
09-07 05:58:49.752: I/dalvikvm(1981):   at dalvik.system.NativeStart.main(Native Method)
09-07 05:58:49.752: D/skia(1981): --- decoder->decode returned false
09-07 05:58:49.752: D/AndroidRuntime(1981): Shutting down VM
09-07 05:58:49.752: W/dalvikvm(1981): threadid=1: thread exiting with uncaught exception (group=0xb3d1fb20)
09-07 05:58:49.752: E/AndroidRuntime(1981): FATAL EXCEPTION: main
09-07 05:58:49.752: E/AndroidRuntime(1981): Process: com.jwy.linearlayout, PID: 1981
09-07 05:58:49.752: E/AndroidRuntime(1981): java.lang.OutOfMemoryError
09-07 05:58:49.752: E/AndroidRuntime(1981): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
09-07 05:58:49.752: E/AndroidRuntime(1981): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:587)
09-07 05:58:49.752: E/AndroidRuntime(1981): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:422)
09-07 05:58:49.752: E/AndroidRuntime(1981): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840)
09-07 05:58:49.752: E/AndroidRuntime(1981): at android.content.res.Resources.loadDrawable(Resources.java:2110)
09-07 05:58:49.752: E/AndroidRuntime(1981): at android.content.res.Resources.getDrawable(Resources.java:700)
09-07 05:58:49.752: E/AndroidRuntime(1981): at android.widget.ImageView.resolveUri(ImageView.java:638)
09-07 05:58:49.752: E/AndroidRuntime(1981): at android.widget.ImageView.setImageResource(ImageView.java:367)
09-07 05:58:49.752: E/AndroidRuntime(1981): at com.jwy.linearlayout.MainActivity.onCreate(MainActivity.java:24)
09-07 05:58:49.752: E/AndroidRuntime(1981): at android.app.Activity.performCreate(Activity.java:5231)
09-07 05:58:49.752: E/AndroidRuntime(1981): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-07 05:58:49.752: E/AndroidRuntime(1981): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
09-07 05:58:49.752: E/AndroidRuntime(1981): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
09-07 05:58:49.752: E/AndroidRuntime(1981): at android.app.ActivityThread.access$800(ActivityThread.java:135)
09-07 05:58:49.752: E/AndroidRuntime(1981): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
09-07 05:58:49.752: E/AndroidRuntime(1981): at android.os.Handler.dispatchMessage(Handler.java:102)
09-07 05:58:49.752: E/AndroidRuntime(1981): at android.os.Looper.loop(Looper.java:136)
09-07 05:58:49.752: E/AndroidRuntime(1981): at android.app.ActivityThread.main(ActivityThread.java:5017)
09-07 05:58:49.752: E/AndroidRuntime(1981): at java.lang.reflect.Method.invokeNative(Native Method)
09-07 05:58:49.752: E/AndroidRuntime(1981): at java.lang.reflect.Method.invoke(Method.java:515)
09-07 05:58:49.752: E/AndroidRuntime(1981): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
09-07 05:58:49.752: E/AndroidRuntime(1981): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
09-07 05:58:49.752: E/AndroidRuntime(1981): at dalvik.system.NativeStart.main(Native Method)


解决方法:把编辑模拟器,将其VM Heap 值由默认的16改为128


关于解决VM heap的问题

标签:android

原文地址:http://blog.csdn.net/wenyan07/article/details/39121065

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!