1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
public class RunTheGarbageCollector { public static void main(String[] args) { /* * To run the garbage collector thread use * public static void gc() method of System class. * * Please note that, calling this method only suggest JVM * to run the garbage collection process. It does not guarantee * that all eligible objects will be garbage collected. */ System.out.println("Suggesting VM to run garbage collector"); System.gc(); System.out.println("Suggested VM to garbage collect objects"); } } |