Note that there are some explanatory texts on larger screens.

plurals
  1. PODefrag/decrease heap size on pre honeycomb
    primarykey
    data
    text
    <p>I developed an app that on startup parses some pretty big amounts of JSON which causes the heap to grow close to its limit. A little later the app is loading several bitmaps. On Honeycomb and above devices, which seem to be using the same memory region for bitmap allocations as well as Java object allocations, this isn't causing any issues as the memory needed for JSON parsing has been freed by then. However on pre-Honeycomb devices it causes OutOfMemoryErrors</p> <p>As the heap size never goes down dalvik seems to not be able to grow the memory reserved for external allocations (e.g. bitmaps).</p> <p>This is one example log output for a crash</p> <pre><code>GC_EXTERNAL_ALLOC freed 601K, 81% free 5504K/27591K, external 4809K/5561K, paused 58ms 586224-byte external allocation too large for this process. </code></pre> <p>As you can see there is plenty of memory available on the heap but not much for external allocation.</p> <p>Is there a way I can force dalvik to defrag and shrink the heap? Or can I force bitmap allocations to happen on the heap instead of memory reserved for external allocations? Or is there any other approach to this problem I'm missing out on?</p> <p>** UPDATE **</p> <p>Here is more log output (the specific device doesn't log dalvik-heap messages):</p> <p>On startup when the JSON gets parsed the dalvik heap grows:</p> <pre><code>GC_CONCURRENT freed 800K, 19% free 12717K/15687K, external 2637K/2773K, paused 2ms+5ms GC_CONCURRENT freed 871K, 19% free 13857K/16903K, external 2637K/2773K, paused 2ms+5ms GC_CONCURRENT freed 1106K, 19% free 14766K/18055K, external 2637K/2773K, paused 3ms+5ms GC_CONCURRENT freed 818K, 16% free 15946K/18951K, external 2637K/2773K, paused 3ms+6ms GC_CONCURRENT freed 825K, 15% free 17151K/20167K, external 2637K/2773K, paused 2ms+6ms GC_CONCURRENT freed 830K, 15% free 18356K/21383K, external 2637K/2773K, paused 2ms+5ms GC_CONCURRENT freed 814K, 14% free 19519K/22535K, external 2637K/2773K, paused 2ms+6ms GC_CONCURRENT freed 823K, 13% free 20720K/23751K, external 2637K/2773K, paused 2ms+5ms GC_CONCURRENT freed 814K, 13% free 21873K/24903K, external 2637K/2773K, paused 3ms+6ms GC_CONCURRENT freed 813K, 12% free 23016K/26055K, external 2637K/2773K, paused 2ms+5ms GC_CONCURRENT freed 1771K, 15% free 23205K/27207K, external 2637K/2773K, paused 2ms+5ms </code></pre> <p>After that's done most of the heap gets freed again successfully:</p> <pre><code>GC_EXPLICIT freed 19207K, 83% free 4735K/27207K, external 2736K/2773K, paused 140ms </code></pre> <p>At this point I have 20 MB free Dalvik heap space and start allocating bitmaps a little later:</p> <pre><code>GC_EXTERNAL_ALLOC freed 254K, 83% free 4814K/27207K, external 2771K/2773K, paused 47ms GC_EXTERNAL_ALLOC freed 721K, 83% free 4880K/27207K, external 3881K/4131K, paused 50ms GC_EXTERNAL_ALLOC freed 235K, 83% free 4870K/27207K, external 5398K/5561K, paused 62ms </code></pre> <p>Total device limit seems to be 32 MB the dalvik heap takes 27 MB of those and never goes down so I run out of external memory space to alloc bitmaps.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload