I made a test program to test the Runtime.freeMemory() method.
public class RuntimeFreeMemory {
public static void main(String[] args) {
Runtime r = Runtime.getRuntime();
System.out.println(r.freeMemory()); // 246939608
String[] arr = new String[10000000];
for (int i = 0; i < 10000000; i++)
arr[i] = new String();
System.out.println(r.freeMemory()); // 517655928
}
}
Of course, these are big numbers, but I really wanted to test it as numbers like 10000 wouldn't cut it. But when I ran it, I got some unexpected numbers. I thought the end free memory would go down or stay somewhat the same as the initial free memory, but instead they went over double what the initial free memory was. I ran this multiple times and it was always something around these values. Can somebody explain this?