Runtime - why is freeMemory() not showing memory consumed correctly?
问题 Below is the code snippet to examine the memory public class TestFreeMemory { public static void main(String ... args){ Runtime rt = Runtime.getRuntime(); System.out.println("Free Memory (Before GC): " + rt.freeMemory()); rt.gc(); System.out.println("Free Memory (After GC1): " + rt.freeMemory()); rt.gc(); // Second time to ensure results are consistent // MAY BE has collected all non-reachable objects System.out.println("Free Memory (After GC2): " + rt.freeMemory()); String s = new String(