title: Android native libraries and memory consumption
body: <p>I'm participating in development of an Android application that uses quite heavy native library (~20Mb). Actual problem is that GC is working very frequently to resume some (but not too much) memory. Multiple times per second.</p>
  
  <pre><code>04-10 12:16:05.391  18940-18951/com.some.demo D/dalvikvm﹕ GC_FOR_ALLOC freed 6120K, 29% free 31708K/44359K, paused 20ms, total 20ms
  04-10 12:16:05.501  18940-18951/com.some.demo D/dalvikvm﹕ GC_FOR_ALLOC freed 6121K, 29% free 31708K/44359K, paused 23ms, total 23ms
  04-10 12:16:05.601  18940-18951/com.some.demo D/dalvikvm﹕ GC_FOR_ALLOC freed 6120K, 29% free 31708K/44359K, paused 23ms, total 23ms
  04-10 12:16:05.702  18940-18951/com.some.demo D/dalvikvm﹕ GC_FOR_ALLOC freed 6120K, 29% free 31708K/44359K, paused 25ms, total 25ms
  04-10 12:16:05.802  18940-18951/com.some.demo D/dalvikvm﹕ GC_FOR_ALLOC freed 6120K, 29% free 31708K/44359K, paused 28ms, total 28ms
  04-10 12:16:05.902  18940-18951/com.some.demo D/dalvikvm﹕ GC_FOR_ALLOC freed 6120K, 29% free 31708K/44359K, paused 28ms, total 28ms
  04-10 12:16:06.002  18940-18951/com.some.demo D/dalvikvm﹕ GC_FOR_ALLOC freed 6120K, 29% free 31708K/44359K, paused 26ms, total 26ms
  04-10 12:16:06.122  18940-18951/com.some.demo D/dalvikvm﹕ GC_FOR_ALLOC freed 6120K, 29% free 31708K/44359K, paused 41ms, total 41ms
  </code></pre>
  
  <p>In Android Device Monitor (Heap tab) tool I can see that >25 MB is allocated by <em>1-byte array (byte[], boolean[])</em>, other parts consuming much lower heap.
  In Allocation Tracker I can see a lot of lines with <em>3133456 byte[]</em> for <em>dalvik.system.NativeStart</em>.</p>
  
  <p>It raises a question: does Android load all native library into memory or am I doing something wrong? I need some good explanation how Android deals with native libraries.</p>
  
  <p>If there is no really effective way to reduce heap space taken by native library (removing dependency isn't an option, because not only Android uses it), then is there any other way to lower frequency of GC?</p>
  
  <p><strong>EDIT:</strong> Adding images to provide more information.</p>
  
  <p>Heap space:
  <img src="https://i.stack.imgur.com/dsddc.png" alt="Heap"></p>
  
  <p>Memory allocation:
  <img src="https://i.stack.imgur.com/qkXF0.png" alt="Allocation"></p>