Skip to Content

Run object finalization using System class

  1. /*
  2.         Run object finalization using System class
  3.         This example shows how to run the object finalization
  4.         by using runFinalization method of Java System class.
  5. */
  6.  
  7. public class RunFinalizationOfObjects {
  8.  
  9.         public static void main(String[] args) {
  10.                
  11.                 /*
  12.                  * To run finalization method of discarded objects use,
  13.                  * public static void runFinalization() method of
  14.                  * System class.
  15.                  *
  16.                  * Please note that calling this method only SUGGESTS the JVM
  17.                  * to run finalize method of discarded objects
  18.                  */
  19.                  
  20.                  System.out.println("Suggesting JVM to run finalize method");
  21.                  System.runFinalization();
  22.                  System.out.println("Suggested JVM to run finalize method");
  23.                  
  24.         }
  25. }