/*
Run the garbage collector using System class
This example shows how to run the garbage collector
by using gc method of Java System class.
*/
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");
}
}
Bookmark/Search this post with: