3

I Brought my app back into view after a while of it sitting idle in the background and I noticed it being very slow and then just not responsive. So then I checked logcat and I see
"Out of memory on a 557296-byte allocation". The last thing I did before my app going idle was add several records to a couple tables in my database. However, the last line in my logcat before the memory error has something to do with a bitmap?..."android.graphics.Bitmap.createBitmap" . I'm not sure how to begin tracking this down.

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
Mike6679
  • 5,547
  • 19
  • 63
  • 108
  • This answer in the link here lead to my finding my memory leaks: [http://stackoverflow.com/questions/1147172/what-android-tools-and-methods-work-best-to-find-memory-resource-leaks][1] [1]: http://stackoverflow.com/questions/1147172/what-android-tools-and-methods-work-best-to-find-memory-resource-leaks – Mike6679 Nov 14 '13 at 22:23

1 Answers1

7

Do you use Bitmaps in your app at all? You must recycle bitmaps using bitmap.recycle(). If you don't recycle your bitmaps you risk an out of memory exception.

If you do have bitmaps I recommend doing this after they are used:

bitmap.recycle();
bitmap = null;

This will assure the bitmap is garbage collected.

If you don't have bitmaps, I recommend using the tools provided in DDMS to monitor heap size. Put your device to sleep and log the changes of the app. I have solved several out of memory exceptions using these tools, and I hope you can to.

vinnymac
  • 116
  • 3
  • Thanks , you pointed me in the right direction and I found this: http://stackoverflow.com/questions/1147172/what-android-tools-and-methods-work-best-to-find-memory-resource-leaks . See answer: "One of the most common errors that I found developing Android Apps is the “java.lang.OutOfMemoryError: Bitmap Size Exceeds VM Budget” error" I have a feeling that this may be my issue. – Mike6679 Nov 08 '13 at 03:40
  • After further research on this, I think my last comment is not correct. I don't want to just deal with the symptoms of my issue but get the the root of my issue, which is one or more memory leaks. This link here : http://stackoverflow.com/questions/12041297/android-tools-to-find-memory-leaks deals with actually how to track down your memory leaks in Android and how to avoid them. – Mike6679 Nov 11 '13 at 16:51