The Lifetime of an Object : Garbage Collection « Language « Java Tutorial

  1. The process of disposing of dead objects is called garbage collection.
  2. Encouraging the Java Virtual Machine (JVM) to do some garbage collecting and recover the memory.
class Sphere {
  double radius; // Radius of a sphere

  Sphere() {


  // Class constructor
  Sphere(double theRadius) {
    radius = theRadius; // Set the radius


public class MainClass {
  public static void main(String[] arg){
    Sphere sp = new Sphere();


1.8.Garbage Collection
1.8.1.Run object finalization using System class
1.8.2.Run the garbage collector using System class
1.8.3.The Lifetime of an Object