JVM garbage collector

In this chapter you will learn:

  1. Run garbage collector and finalization methods

Run garbage collector and finalization methods

  • void gc() Runs the garbage collector.
  • void runFinalization() Runs the finalization methods of any objects pending finalization.
public class Main {
  public static void main(String[] args) {
    Runtime runtime = Runtime.getRuntime();
//j  ava 2 s .co  m
    runtime.gc();
    runtime.runFinalization();
    
  }
}

Next chapter...

What you will learn in the next chapter:

  1. Exit and halt Java virtual machine
  2. How to add a shut down hook
Home » Java Tutorial » Utility Classes
Java standard stream
Java system property get and set
Current time in millis second and nano second
Random UUID
JVM memory
JVM garbage collector
JVM shutting down
Processor count
OS system commands
Random class
Random value
Random value range
Compile Java source code
Timer and TimerTask