public class Test {
public static void main(String[] args) {
Runtime runtime=Runtime.getRuntime();
System.out.println("Total Memory: "+runtime.totalMemory());
System.out.println("Free Memory: "+runtime.freeMemory());
for(int i=0;i<15000;i++){
new Test();
}
System.out.println("Free Memory, after creating 15000 instance: "+runtime.freeMemory());
System.gc();
System.out.println("Free Memory after gc(): "+runtime.freeMemory());
}
} |
public class Test {
public static void main(String[] args) {
Runtime runtime=Runtime.getRuntime();
System.out.println("Total Memory: "+runtime.totalMemory());
System.out.println("Free Memory: "+runtime.freeMemory());
for(int i=0;i<15000;i++){
new Test();
}
System.out.println("Free Memory, after creating 15000 instance: "+runtime.freeMemory());
System.gc();
System.out.println("Free Memory after gc(): "+runtime.freeMemory());
}
}