More free memory?
I have a simple test in which I allocate big long array and then I free that array and call JVM garabage collector.
But I find out I have more free memory afterward (using the runtime.freeMemory() call)
Did I do something wrong? Or could some one please tell me why?
Thanks.
Sam
-
The result:
========
Before Allocate ...
total memory 2031616
free memory 1886232<-- free memory when I start
After Allocate ...
total memory 2031616
free memory 1094352
After gc ...
total memory 2031616
free memory 1894432<-- more free memory than I start
My program:
=========
public static void main(String args[])
{
System.out.println ("Before Allocate ...");
System.out.println ("total memory " + Runtime.getRuntime().totalMemory());
System.out.println ("free memory " + Runtime.getRuntime().freeMemory());
long[] testLongArray = new long[100000];
System.out.println ("After Allocate ...");
System.out.println ("total memory " + Runtime.getRuntime().totalMemory());
System.out.println ("free memory " + Runtime.getRuntime().freeMemory());
testLongArray = null;
System.gc();
System.out.println ("After gc ...");
System.out.println ("total memory " + Runtime.getRuntime().totalMemory());
System.out.println ("free memory " + Runtime.getRuntime().freeMemory());
}

