title: When does Dalvik heap size increase?
body: <p>I recently encountered some cases where heap size was increased without performing GC.<br>
  Example - At the beginning, 746KB(evaluated using Runtime.getRuntime().freeMemory()) of free space was available. 512KB was required to allocate a Bitmap of size 512*512(RGB_565). Without doing a de-frag, the heap size was increased. The free space in the heap was just reduced by 3 KB. Similar pattern was repeated 20 times in a row. No GC message was printed in-between these allocations. Each alloc took ~1ms of time.  </p>
  
  <pre><code>for (int i = 0; i&lt;20; i++) {
    long start = System.currentTimeMillis();
    System.out.println("Free space:"+Runtime.getRuntime().freeMemory());
    System.out.println("Heap size:"+Runtime.getRuntime().totalMemory());
    list.add(Bitmap.createBitmap(512, 512, Bitmap.Config.RGB_565));
    System.out.println(System.currentTimeMillis()-start);
  }
  </code></pre>
  
  <p>Doesn't Dalvik always perform a GC before increasing heap size?</p>
  
  <p>Thanks in advance. Please let me know if any more information is required.</p>