/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
 class GCTest
{
	public static void main(String[] args)
	{
		GCTest test;
		// Without the null assignment
		test = create(0);
		test = create(1);
		test = null;
		System.gc();
		
		try {Thread.sleep(10);} catch (Exception e){}
		System.out.println();
		
		// With the null assignment
		test = create(2);
		test = null;
		test = create(3);
		test = null;
		System.gc();
		
	}
	
	private int id;
	
	public GCTest(int id)
	{
		this.id = id;
		System.out.println("Created " + id);
	}
	
	private static GCTest create(int id)
	{
		System.gc();
		try {Thread.sleep(10);} catch (Exception e){}
		return new GCTest(id);
	}
	
	@Override
	protected void finalize() throws Throwable
	{
		super.finalize();
		System.out.println("Finalize " + id + " from Thread " + Thread.currentThread().getName());
	}

}
