How to run the garbage collector by using gc method of System class. - Java Java Virtual Machine

Java examples for Java Virtual Machine:Utility

Description

How to run the garbage collector by using gc method of System class.

Demo Code


public class Main {
 
        public static void main(String[] args) {
                 System.out.println("Suggesting VM to run garbage collector");
                 System.gc();// w  w  w  .  ja  va  2 s.c o  m
                 System.out.println("Suggested VM to garbage collect objects");
        }
}

Result


Related Tutorials