//: c04:Garbage.java // From 'Thinking in Java, 2nd ed.' by Bruce Eckel // www.BruceEckel.com. See copyright notice in CopyRight.txt. // Demonstration of the garbage // collector and finalization class Chair { static boolean f = false; static int created = 0; int i; Chair() { i = ++created; if ( (i % 100000) == 0) System.out.print("."); } public void finalize() { f = true; } } public class Garbage { public static void main(String[] args) { // As long as the flag hasn't been set, make Chairs: while(!Chair.f) { new Chair(); } System.out.println( "\nTotal chairs created = " + Chair.created ); } } ///: