gpt4 book ai didi

android - 内存不足致命异常

转载 作者:搜寻专家 更新时间:2023-11-01 09:08:15 24 4
gpt4 key购买 nike

我有一个包含 12 个 ImageView 的 Activity 。在 onCreate 方法中,我使用 BitmapFactory.decodeStream(...) 在这些 ImageView 中加载了 12 张照片。

当我来到这个页面并返回 10 次时,我得到以下内存不足异常。

为什么会出现此错误以及如何释放资源以防止出现此异常?

谢谢,

04-24 14:41:00.050: D/TextView(7586): Constructor - Got appearance for textColorPrimaryInverse
04-24 14:41:00.050: D/TextView(7586): Constructor -- Got mEditTextBackgroundColor
04-24 14:41:00.130: I/dalvikvm-heap(7586): Clamp target GC heap from 48.878MB to 48.000MB
04-24 14:41:00.130: D/dalvikvm(7586): GC_FOR_ALLOC freed 495K, 2% free 47950K/48775K, paused 44ms
04-24 14:41:00.130: I/dalvikvm-heap(7586): Forcing collection of SoftReferences for 404616-byte allocation
04-24 14:41:00.180: I/dalvikvm-heap(7586): Clamp target GC heap from 48.856MB to 48.000MB
04-24 14:41:00.180: D/dalvikvm(7586): GC_BEFORE_OOM freed 23K, 2% free 47926K/48775K, paused 48ms
04-24 14:41:00.180: E/dalvikvm-heap(7586): Out of memory on a 404616-byte allocation.
04-24 14:41:00.180: I/dalvikvm(7586): "main" prio=5 tid=1 RUNNABLE
04-24 14:41:00.180: I/dalvikvm(7586): | group="main" sCount=0 dsCount=0 obj=0x40a54460 self=0x1ad5828
04-24 14:41:00.180: I/dalvikvm(7586): | sysTid=7586 nice=0 sched=0/0 cgrp=default handle=1074742408
04-24 14:41:00.180: I/dalvikvm(7586): | schedstat=( 14073874000 2242143000 19299 ) utm=1301 stm=106 core=1
04-24 14:41:00.180: I/dalvikvm(7586): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
04-24 14:41:00.180: I/dalvikvm(7586): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:493)
04-24 14:41:00.180: I/dalvikvm(7586): at org.mabna.order.utils.Utilities.decodeFile(Utilities.java:1220)
04-24 14:41:00.180: I/dalvikvm(7586): at org.mabna.order.businessLayer.db.BoInvProducts.getProductPhoto(BoInvProducts.java:107)
04-24 14:41:00.180: I/dalvikvm(7586): at org.mabna.order.ui.ActProductsGallery.loadPageImages(ActProductsGallery.java:729)
04-24 14:41:00.180: I/dalvikvm(7586): at org.mabna.order.ui.ActProductsGallery.selectItemInGallery(ActProductsGallery.java:611)
04-24 14:41:00.180: I/dalvikvm(7586): at org.mabna.order.ui.ActProductsGallery.onCreate(ActProductsGallery.java:315)
04-24 14:41:00.180: I/dalvikvm(7586): at android.app.Activity.performCreate(Activity.java:4465)
04-24 14:41:00.180: I/dalvikvm(7586): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-24 14:41:00.180: I/dalvikvm(7586): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
04-24 14:41:00.180: I/dalvikvm(7586): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
04-24 14:41:00.180: I/dalvikvm(7586): at android.app.ActivityThread.access$600(ActivityThread.java:123)
04-24 14:41:00.180: I/dalvikvm(7586): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
04-24 14:41:00.180: I/dalvikvm(7586): at android.os.Handler.dispatchMessage(Handler.java:99)
04-24 14:41:00.180: I/dalvikvm(7586): at android.os.Looper.loop(Looper.java:137)
04-24 14:41:00.180: I/dalvikvm(7586): at android.app.ActivityThread.main(ActivityThread.java:4424)
04-24 14:41:00.180: I/dalvikvm(7586): at java.lang.reflect.Method.invokeNative(Native Method)
04-24 14:41:00.180: I/dalvikvm(7586): at java.lang.reflect.Method.invoke(Method.java:511)
04-24 14:41:00.180: I/dalvikvm(7586): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-24 14:41:00.180: I/dalvikvm(7586): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-24 14:41:00.180: I/dalvikvm(7586): at dalvik.system.NativeStart.main(Native Method)
04-24 14:41:00.180: D/skia(7586): --- decoder->decode returned false
04-24 14:41:00.180: D/AndroidRuntime(7586): Shutting down VM
04-24 14:41:00.180: W/dalvikvm(7586): threadid=1: thread exiting with uncaught exception (group=0x40a531f8)
04-24 14:41:00.180: E/AndroidRuntime(7586): FATAL EXCEPTION: main
04-24 14:41:00.180: E/AndroidRuntime(7586): java.lang.OutOfMemoryError
04-24 14:41:00.180: E/AndroidRuntime(7586): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
04-24 14:41:00.180: E/AndroidRuntime(7586): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:493)
04-24 14:41:00.180: E/AndroidRuntime(7586): at org.mabna.order.utils.Utilities.decodeFile(Utilities.java:1220)
04-24 14:41:00.180: E/AndroidRuntime(7586): at org.mabna.order.businessLayer.db.BoInvProducts.getProductPhoto(BoInvProducts.java:107)
04-24 14:41:00.180: E/AndroidRuntime(7586): at org.mabna.order.ui.ActProductsGallery.loadPageImages(ActProductsGallery.java:729)
04-24 14:41:00.180: E/AndroidRuntime(7586): at org.mabna.order.ui.ActProductsGallery.selectItemInGallery(ActProductsGallery.java:611)
04-24 14:41:00.180: E/AndroidRuntime(7586): at org.mabna.order.ui.ActProductsGallery.onCreate(ActProductsGallery.java:315)
04-24 14:41:00.180: E/AndroidRuntime(7586): at android.app.Activity.performCreate(Activity.java:4465)
04-24 14:41:00.180: E/AndroidRuntime(7586): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-24 14:41:00.180: E/AndroidRuntime(7586): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
04-24 14:41:00.180: E/AndroidRuntime(7586): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
04-24 14:41:00.180: E/AndroidRuntime(7586): at android.app.ActivityThread.access$600(ActivityThread.java:123)
04-24 14:41:00.180: E/AndroidRuntime(7586): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
04-24 14:41:00.180: E/AndroidRuntime(7586): at android.os.Handler.dispatchMessage(Handler.java:99)
04-24 14:41:00.180: E/AndroidRuntime(7586): at android.os.Looper.loop(Looper.java:137)
04-24 14:41:00.180: E/AndroidRuntime(7586): at android.app.ActivityThread.main(ActivityThread.java:4424)
04-24 14:41:00.180: E/AndroidRuntime(7586): at java.lang.reflect.Method.invokeNative(Native Method)
04-24 14:41:00.180: E/AndroidRuntime(7586): at java.lang.reflect.Method.invoke(Method.java:511)
04-24 14:41:00.180: E/AndroidRuntime(7586): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-24 14:41:00.180: E/AndroidRuntime(7586): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-24 14:41:00.180: E/AndroidRuntime(7586): at dalvik.system.NativeStart.main(Native Method)
04-24 14:41:01.350: I/Process(7586): Sending signal. PID: 7586 SIG: 9

最佳答案

也许,用最接近您的 ImageViews 的大小解码您的图像(参见:Strange out of memory issue while loading an image to a Bitmap object)

关于android - 内存不足致命异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10278686/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com