title: Do Dalvik VM Processes Release System RAM?
body: <p>The Android developer documentation, as part of Project Svelte (motto: "You ever try fitting Bugdroid into skinny jeans?!?"), has a page on <a href="http://developer.android.com/training/articles/memory.html" rel="noreferrer">Managing Your App's Memory</a>. It contains:</p>
  
  <blockquote>
    <p>When the user navigates to a different app and your UI is no longer visible, you should release any resources that are used by only your UI. Releasing UI resources at this time can significantly increase the system's capacity for cached processes, which has a direct impact on the quality of the user experience.</p>
  </blockquote>
  
  <p>and:</p>
  
  <blockquote>
    <p><code>TRIM_MEMORY_RUNNING_LOW</code>: Your app is running and not considered killable, but the device is running much lower on memory so you should release unused resources to improve system performance (which directly impacts your app's performance).</p>
  </blockquote>
  
  <p>and the like.</p>
  
  <p>However, these would only make sense if "releasing resources" would actually affect system RAM somehow.</p>
  
  <p>I was under the impression that the Dalvik VM behaved like the Java VM does (or perhaps "did", if they changed it when I wasn't looking). AFAIK, the Java VM allocates system RAM to increase the heap size but never releases it -- once allocated, it remains part of the heap space for as long as the process runs.</p>
  
  <p>If the Dalvik VM behaves the same way, then I fail to see how increasing the amount of unallocated heap space in our process would have any impact on the overall system performance. Now, freeing up heap space for our process is a good thing, and perhaps doing so would decrease the likelihood of us needing <em>more</em> system RAM in the future... but that's not what the documentation implies. The documentation states "Releasing UI resources at this time can significantly increase the system's capacity for cached processes"; it does not say "Releasing UI resources at this time has no immediate impact but will help reduce your app's system RAM footprint in the future".</p>
  
  <p>Now, had the instructions told us to release memory allocated via the NDK, that would make sense, as that occurs outside the Dalvik heap and would affect system RAM. But the documentation does not draw that distinction.</p>
  
  <p>Does the Dalvik VM actually release allocated RAM back to the system, other than by terminating the process? If so, when? And, to a lesser extent, how is that done, considering that the garbage collector is non-compacting and non-copying?</p>
  
  <p>Thanks!</p>