import java.util.*;
class GarbageCollection{
public static void main(String s[]) throws Exception
{ Runtime rs = Runtime.getRuntime();
System.out.println("Free memory in JVM before Garbage Collection = "+rs.freeMemory());
rs.gc();//garbage collection
System.out.println("Free memory in JVM after Garbage Collection = "+rs.freeMemory());
//We can also use
System.gc();
No comments:
Post a Comment