19

My application is causing these dreaded GC_FOR_ALLOC occur way to many times in specific locations (methods):

12-29 22:20:30.229: D/dalvikvm(10592): GC_FOR_ALLOC freed 1105K, 14% free 10933K/12615K, paused 33ms, total 34ms
12-29 22:20:30.260: D/dalvikvm(10592): GC_FOR_ALLOC freed 337K, 13% free 11055K/12615K, paused 25ms, total 26ms
12-29 22:20:30.288: D/dalvikvm(10592): GC_FOR_ALLOC freed 278K, 14% free 10951K/12615K, paused 24ms, total 24ms
12-29 22:20:30.495: D/dalvikvm(10592): GC_CONCURRENT freed 633K, 11% free 11317K/12615K, paused 16ms+3ms, total 79ms
12-29 22:20:30.495: D/dalvikvm(10592): WAIT_FOR_CONCURRENT_GC blocked 16ms
12-29 22:20:30.499: D/dalvikvm(10592): WAIT_FOR_CONCURRENT_GC blocked 15ms

It's clear to me that I am doing something wrong in regard to memory management (yes, garbage collection is great but still doesn't free me from some responsibility to know when & how to allocate).

Can you recommend a troubleshooting approach or technique that can lead me to the offending lines of code and possible solutions?

Cœur
  • 37,241
  • 25
  • 195
  • 267
srf
  • 2,410
  • 4
  • 28
  • 41
  • 6
    You may want to read [this blog post](http://www.curious-creature.org/2009/02/07/track-memory-allocations-on-android/), written by Romain Guy (yeah, that Google engineer who talks at I/O several times each year). – Cat Dec 30 '12 at 04:01
  • @Eric That's exactly the kind of pointers I need. Thanks! (BTW, does Romain Guy work with [Patrick](http://www.youtube.com/watch?v=_CruQY55HOk)?) – srf Dec 30 '12 at 04:09
  • 1
    I don't think so. Patrick is on the Chrome team and Romain is on the Android team.. how Patrick ended up in an Android talk? I don't know! :P – Cat Dec 30 '12 at 04:31

1 Answers1

55

Android DDMS, which is part of Android development tools in eclipse, has very useful tools that you can use for profiling and memory allocation tracking.

The below screenshot highlights some of these tools (all under DDMS), some tools need to be activated by clicking the corresponding button in the left panel (highlighted in red) and then you can see the values (some with graphs) in the right panel by selecting the tab you want to watch (highlighted in Blue)

Heap and Allocation Tracker will be very useful in your case.

eclipse screenshot showing profiling and memory allocation tools

iTech
  • 18,192
  • 4
  • 57
  • 80