gpt4 book ai didi

Android:字节分配内存不足(android.graphics.Bitmap)

转载 作者:太空宇宙 更新时间:2023-11-03 12:19:41 25 4
gpt4 key购买 nike

我的应用程序在后台闲置了一段时间后,我将其重新显示在 View 中,我注意到它非常慢,然后就是没有响应。然后我检查了 logcat,我看到了
“557296 字节分配内存不足”。在我的应用程序闲置之前,我做的最后一件事是向数据库中的几个表添加几条记录。但是,内存错误之前我的 logcat 中的最后一行与位图有关?..."android.graphics.Bitmap.createBitmap"。我不确定如何开始追踪它。

11-07 20:32:22.940: D/PMS(599): acquireWL(42e31570): PARTIAL_WAKE_LOCK  CM_static 0x1 13857 10166
11-07 20:32:22.950: D/PMS(599): releaseWL(42e31570): PARTIAL_WAKE_LOCK CM_static 0x1
11-07 20:32:23.060: E/dalvikvm(16038): can't open /data/misc/app_oom.hprof: Permission denied
11-07 20:32:23.100: E/dalvikvm-heap(16038): hprofDumpHeap failed with result: -1
11-07 20:32:23.100: E/dalvikvm-heap(16038): After hprofDumpHeap for process
11-07 20:32:23.100: E/dalvikvm(16038): Out of memory: Heap Size=196608KB, Allocated=188196KB, Limit=196608KB, Proc Limit=196608KB
11-07 20:32:23.100: E/dalvikvm(16038): Extra info: Footprint=196512KB, Allowed Footprint=196608KB, Trimmed=2828KB
11-07 20:32:23.200: I/dalvikvm-heap(16038): Clamp target GC heap from 193.013MB to 192.000MB
11-07 20:32:23.200: I/dalvikvm-heap(16038): Forcing collection of SoftReferences for 557296-byte allocation
11-07 20:32:23.240: D/MtpDatabase(25526): sessionStarted
11-07 20:32:23.310: I/dalvikvm-heap(16038): Clamp target GC heap from 193.013MB to 192.000MB
11-07 20:32:23.310: E/dalvikvm-heap(16038): Out of memory on a 557296-byte allocation.
11-07 20:32:23.310: I/dalvikvm(16038): "main" prio=5 tid=1 RUNNABLE
11-07 20:32:23.310: I/dalvikvm(16038): | group="main" sCount=0 dsCount=0 obj=0x41f267e8 self=0x41f113b8
11-07 20:32:23.310: I/dalvikvm(16038): | sysTid=16038 nice=0 sched=0/0 cgrp=apps handle=1074839548
11-07 20:32:23.310: I/dalvikvm(16038): | state=R schedstat=( 0 0 0 ) utm=61459 stm=7538 core=3
11-07 20:32:23.310: I/dalvikvm(16038): at android.graphics.Bitmap.nativeCreate(Native Method)
11-07 20:32:23.310: I/dalvikvm(16038): at android.graphics.Bitmap.createBitmap(Bitmap.java:1041)
11-07 20:32:23.310: I/dalvikvm(16038): at android.graphics.Bitmap.createBitmap(Bitmap.java:983)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.View.buildDrawingCache(View.java:13312)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.View.getDrawingCache(View.java:13161)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.View.draw(View.java:13859)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.ViewGroup.drawChild(ViewGroup.java:3105)
11-07 20:32:23.310: I/dalvikvm(16038): at android.widget.ListView.drawChild(ListView.java:3590)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2934)
11-07 20:32:23.310: I/dalvikvm(16038): at android.widget.AbsListView.dispatchDraw(AbsListView.java:2520)
11-07 20:32:23.310: I/dalvikvm(16038): at android.widget.ListView.dispatchDraw(ListView.java:3560)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.View.draw(View.java:14175)
11-07 20:32:23.310: I/dalvikvm(16038): at android.widget.AbsListView.draw(AbsListView.java:3993)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.View.draw(View.java:14053)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.ViewGroup.drawChild(ViewGroup.java:3105)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2934)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.View.draw(View.java:14175)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.View.draw(View.java:14053)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.ViewGroup.drawChild(ViewGroup.java:3105)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2934)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.View.draw(View.java:14051)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.ViewGroup.drawChild(ViewGroup.java:3105)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2934)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.View.draw(View.java:14051)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.ViewGroup.drawChild(ViewGroup.java:3105)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2934)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.View.draw(View.java:14175)
11-07 20:32:23.310: I/dalvikvm(16038): at android.widget.FrameLayout.draw(FrameLayout.java:467)
11-07 20:32:23.310: I/dalvikvm(16038): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2312)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2761)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2674)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2491)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2048)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1119)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5849)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:786)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.Choreographer.doCallbacks(Choreographer.java:586)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.Choreographer.doFrame(Choreographer.java:546)
11-07 20:32:23.310: I/dalvikvm(16038): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:771)
11-07 20:32:23.310: I/dalvikvm(16038): at android.os.Handler.handleCallback(Handler.java:730)
11-07 20:32:23.310: I/dalvikvm(16038): at android.os.Handler.dispatchMessage(Handler.java:92)
11-07 20:32:23.310: I/dalvikvm(16038): at android.os.Looper.loop(Looper.java:158)
11-07 20:32:23.310: I/dalvikvm(16038): at android.app.ActivityThread.main(ActivityThread.java:5789)
11-07 20:32:23.310: I/dalvikvm(16038): at java.lang.reflect.Method.invokeNative(Native Method)
11-07 20:32:23.310: I/dalvikvm(16038): at java.lang.reflect.Method.invoke(Method.java:525)
11-07 20:32:23.310: I/dalvikvm(16038): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
11-07 20:32:23.310: I/dalvikvm(16038): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:843)
11-07 20:32:23.310: I/dalvikvm(16038): at dalvik.system.NativeStart.main(Native Method)
11-07 20:32:23.310: E/dalvikvm-heap(16038): Generating hprof for process: com.test.myApp PID: 16038

最佳答案

您是否在您的应用中使用位图?您必须使用 bitmap.recycle() 回收位图。如果您不回收您的位图,您将面临内存不足异常的风险。

如果您有位图,我建议您在使用后执行此操作:

bitmap.recycle();
bitmap = null;

这将确保位图被垃圾回收。

如果您没有位图,我建议使用 DDMS to monitor heap size 中提供的工具.让您的设备进入休眠状态并记录应用程序的更改。我已经使用这些工具解决了几个内存不足的异常,我希望你能做到。

关于Android:字节分配内存不足(android.graphics.Bitmap),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19850267/

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