Java - Runtime.freeMemory()
<p>I was trying to see usage of Runtime.freeMemory().</p>

<p>Documentation  says it 'Returns the amount of free memory in the Java Virtual Machine'</p>

<p>I executed a simple program test this. Program below:</p>

<pre><code>public class Test {

 public static void main(String a[]) throws Exception {
    System.out.println("Total memory: " +Runtime.getRuntime().totalMemory());
    System.out.println("Free memory: " +Runtime.getRuntime().freeMemory());
    Integer intArr[]= new Integer[10000];
    for(int i =0; i&lt;10000;i++){
        intArr[i] = new Integer(i+500);
    }
    System.out.println("Free memory: " +Runtime.getRuntime().freeMemory());
    System.out.println("sample print :"+ intArr[0]);
    System.out.println("sample print :"+ intArr[5000]);
    System.out.println("sample print :"+ intArr[9999]);
 }  
}
</code></pre>

<p>Output:</p>

<p>Total memory: 67108864</p>

<p>Free memory: 61822408  &lt; Before allocating 10000 objects></p>

<p>Free memory: 61822408  &lt; Size remains same even after allocating 10000 objects. why?></p>

<p>sample print :500</p>

<p>sample print :5500</p>

<p>sample print :10499</p>

<p>Since the objects are created on heap, the 'Free memory' value printed second time should be less than the first output, right?</p>

<p>But it prints same value. Can anyone please explain why it print same value? </p>
