我使用自定义列表适配器制作了一个列表视图,其中包含文本和图像 IN 侧列表。它运行良好,但是当我反复向上滚动列表视图然后应用程序崩溃并且在 log cat 中显示堆大小问题。
我应该怎么做才能解决这个问题?当我在 HTC one V(4.0 API) 上测试应用程序时,Low Api 版本没有出现问题,然后只有它在滚动时崩溃,它可以滚动 3 或 4 次,但做更多滚动时它会挂起并用力关闭堆大小问题。
堆栈跟踪:
I/dalvikvm(20978): at dalvik.system.NativeStart.main(Native Method)
09-03 07:58:33.796: E/dalvikvm(20978): Out of memory: Heap Size=131107KB, Allocated=130843KB, Limit=49152KB
09-03 07:58:33.796: E/dalvikvm(20978): Extra info: Footprint=131043KB, Allowed Footprint=131107KB, Trimmed=1096KB
09-03 07:58:33.796: D/skia(20978): --- decoder->decode returned false
09-03 07:58:33.796: D/AndroidRuntime(20978): Shutting down VM
09-03 07:58:33.796: W/dalvikvm(20978): threadid=1: thread exiting with uncaught exception (group=0x40ab8228)
09-03 07:58:33.826: E/AndroidRuntime(20978): FATAL EXCEPTION: main
09-03 07:58:33.826: E/AndroidRuntime(20978): java.lang.OutOfMemoryError: (Heap Size=131107KB, Allocated=130843KB)
09-03 07:58:33.826: E/AndroidRuntime(20978): at android.graphics.BitmapFactory.nativeDecodeFile(Native Method)
09-03 07:58:33.826: E/AndroidRuntime(20978): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:373)
09-03 07:58:33.826: E/AndroidRuntime(20978): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:443)
09-03 07:58:33.826: E/AndroidRuntime(20978): at com.raila.controller.ImageDownloader.download(ImageDownloader.java:90)
09-03 07:58:33.826: E/AndroidRuntime(20978): at com.raila.view.NewsActivity$ItemsAdapter.getView(NewsActivity.java:166)
09-03 07:58:33.826: E/AndroidRuntime(20978): at android.widget.AbsListView.obtainView(AbsListView.java:2054)
09-03 07:58:33.826: E/AndroidRuntime(20978): at android.widget.ListView.makeAndAddView(ListView.java:2004)
09-03 07:58:33.826: E/AndroidRuntime(20978): at android.widget.ListView.fillUp(ListView.java:889)
09-03 07:58:33.826: E/AndroidRuntime(20978): at android.widget.ListView.fillGap(ListView.java:829)
09-03 07:58:33.826: E/AndroidRuntime(20978): at android.widget.AbsListView.trackMotionScroll(AbsListView.java:4636)
09-03 07:58:33.826: E/AndroidRuntime(20978): at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:3899)
09-03 07:58:33.826: E/AndroidRuntime(20978): at android.os.Handler.handleCallback(Handler.java:607)
09-03 07:58:33.826: E/AndroidRuntime(20978): at android.os.Handler.dispatchMessage(Handler.java:92)
09-03 07:58:33.826: E/AndroidRuntime(20978): at android.os.Looper.loop(Looper.java:154)
09-03 07:58:33.826: E/AndroidRuntime(20978): at android.app.ActivityThread.main(ActivityThread.java:4974)
09-03 07:58:33.826: E/AndroidRuntime(20978): at java.lang.reflect.Method.invokeNative(Native Method)
09-03 07:58:33.826: E/AndroidRuntime(20978): at java.lang.reflect.Method.invoke(Method.java:511)
09-03 07:58:33.826: E/AndroidRuntime(20978): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
-03 07:58:33.826: E/AndroidRuntime(20978): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-03 07:58:33.826: E/AndroidRuntime(20978): at dalvik.system.NativeStart.main(Native Method)
09-03 07:58:33.977: I/dalvikvm-heap(20978): Clamp target GC heap from 134.749MB to 128.000MB
09-03 07:58:33.987: D/dalvikvm(20978): GC_CONCURRENT freed 388K, 1% free 130500K/131043K, paused 2ms+33ms
09-03 07:58:36.379: D/Process(20978): killProcess, pid=20978