主要介绍Android图片oom问题的原因及解决方法,顺带提及Dalvik heap size。
1、现象
很多朋友应该都碰到过下面这个异常
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
FATAL EXCEPTION: main java.lang.OutOfMemoryError: bitmap size exceeds VM budget at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) at android.graphics.BitmapFactory.nativeDecodeStream(Native Method) at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:484) at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:284) at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:309) at cn.trinea.appsearch.util.Cache$2.onImageLoaded(Cache.java:88) at cn.trinea.appsearch.cache.ImageSDCardCache$MyHandler.handleMessage(ImageSDCardCache.java:390) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:130) at android.app.ActivityThread.main(ActivityThread.java:3703) 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:841) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599) at dalvik.system.NativeStart.main(Native Method) |
多图片的程序运行一段时间或是monkey test极易出现上面的异常信息,表示图片的[......]