The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Re: "Thinking in Java" example and forced finalization

Posted by David Pinhasik on December 02, 2001 at 4:12 AM

> Which example were you looking at?


Thinking in Java, 2nd. edition. Chapter 4, excercises 11 and 12. His example is on page 211 in the section titled "You must perform cleanup" and creates Chair objects, finalizes some of them whenever the gc wants to, and at the end of program, forces finalization via a call to System.gc().

Thanks,
David

ps. I am now on excercise 13 (creating a Tank, filling and emptying it, and enforcing a "death condition" by checking in the finalize() method. Here also I am experiencing the problem. I call the gc, but my finalize() method is not being called. However, I added a print line, and it had no effect. What am I missing? Why can't I force finalization, as he says I can? I haven't tried System.runFinalization, which shouldn't make a difference, anyways, according to the book.

pps. I just read something that may explain the problem "If System.gc() is called, then finalization happens to all the objects. This was not necessarily the case with previous implementations of the JDK, although the documentation claimed otherwise" I am using Visual Age for Java 3.5. I don't think this should be a problem, but who knows?

David



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us