title: Increase initial amount of the free memory in an Android application
body: <p>I'd like to know if this is possible. My purpose is to decrease the number of GC operations during a long processing.</p>
  <hr />
  <p>In an Android application I check the free and max heap size with:</p>
  <pre><code>Runtime runtime = Runtime.getRuntime();
  ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
  
  System.out.println( &quot;freeMemory: &quot; + runtime.freeMemory() );
  System.out.println( &quot;maxMemory: &quot; + runtime.maxMemory() );
  System.out.println( &quot;memoryClass: &quot; + am.getMemoryClass() );
  </code></pre>
  <p>In LogCat for the <code>onCreate()</code> method it says:</p>
  <pre><code>freeMemory: 5678992
  maxMemory: 50331648
  memoryClass: 48
  </code></pre>
  <p>Then I perform some long <code>String</code> operations and in the middle of the processing I check the memory again:</p>
  <pre><code>freeMemory: 1833176
  </code></pre>
  <p>(I don't post the code of this processing because for the actual stage I don't perform the <code>Java</code> code optimization, only working with the memory).</p>
  <p>And the GC runs to free the memory. This slows the application:</p>
  <pre><code>GC_CONCURRENT freed 4760K, 42% free 7653K/13123K, paused 12ms+13ms, total 43ms
  GC_CONCURRENT freed 2012K, 42% free 7688K/13123K, paused 12ms+2ms, total 31ms
  GC_CONCURRENT freed 1839K, 42% free 7662K/13123K, paused 12ms+12ms, total 40ms
  </code></pre>
  <p>At the end of the processing the free memory is:</p>
  <pre><code>freeMemory: 4605040
  </code></pre>
  <hr />
  <p>As the documentation says:</p>
  <ul>
  <li><p><code>Runtime.freeMemory()</code></p>
  <blockquote>
  <p>Returns the number of bytes currently available on the heap without expanding the heap.</p>
  </blockquote>
  </li>
  <li><p><code>Runtime.maxMemory()</code></p>
  <blockquote>
  <p>Returns the maximum number of bytes the heap can expand to.</p>
  </blockquote>
  </li>
  </ul>
  <p>As I understand the <code>Runtime.maxMemory()</code> shows the memory which shouldn't be overflowed to prevent the <code>OutOfMemoryError</code>. And exceeding the <code>Runtime.freeMemory()</code> amount just leads to the free memory expanding.</p>
  <p>So the GC freeing operations in my code were caused by the low amount of the free memory left after memory consuming actions (when it said: <code>freeMemory: 1 833 176</code>). But the total amount of the free memory wasn't expanded, only freed to stay within the same starting limit.</p>
  <p>And I suppose the initial amount of the free memory also wasn't very high (because in the <code>onCreate()</code> method it showed <code>5 678 992</code>). And if I had initially about 10 MB free the GC wouldn't happen and thus the application would perform the processing faster.</p>
  <hr />
  <p><strong>So the question is:</strong> Is there a way I can increase the initial amount of the free memory to prevent frequent GC calls and memory expanding?</p>
  <p>Thanks.</p>