当前位置 : 主页 > 手机开发 > android >

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

来源:互联网 收集:自由互联 发布时间:2021-06-11
我将应用程序带回到视野中,一段时间后它在后台闲置,我注意到它很慢,然后才响应.那么我检查了logcat,我明白了 “557296字节分配的内存不足”.在我的应用程序空闲之前我做的最后一件事
我将应用程序带回到视野中,一段时间后它在后台闲置,我注意到它很慢,然后才响应.那么我检查了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
你在应用程序中使用Bitmaps吗?您必须使用bitmap.recycle()回收位图.如果不回收位图,则存在内存不足异常的风险.

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

bitmap.recycle();
bitmap = null;

这将确保位图被垃圾收集.

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

网友评论