Hey,

does anyone happen to know which method is called by the garbage collector on an object when garbage collection determines that there are no more references to the object?

and does anyone happen to know which class contains the definition of this method?

Thanks :)

itchap

This is definately a homework question, but I will give you a hint.

Read the API for the class that all other classes extend implicitly.

the API docs won't help you there, you'll need to read a decent book about Java instead.
Chapter 1 of the langauge specification for example has the answer you need (though it doesn't go into minute detail, but neither does your question).
You can download it as a PDF or set of HTML documents from Sun, read it online on their website, or buy it as a book.

http://java.sun.com/javase/reference/api.jsp

Sorry to disagree, but a quick quote from the api

finalize()
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

From the Object class API doc.

Does this not answer the exact question he asked?

not completely, as the text isn't quite correct :)

there are in fact conditions under which finalize will not be called even when there are no more references to an object and the object is being garbage collected.

True, but in the context of his homework, I believe that this is exactly what his teacher was looking, and the answer I wished to provide.

The other circumstances are exceptions/special cases, and, in general, do not need to be worried about.

Unless his question was not homework, but rather some stuff he was playing with that did not give the expected results.

;-)

If however you don't take care of the exceptional conditions you're liable to be bitten by them.
Think of using finalize to close database resources and files. Sounds perfectly logical, but is extremely dangerous.

Hi Guys,

Thanks for the help , the finalize() methode is what i was looking for. Your tips and help are very much appreaciated.

Thanks once again,

itchap :)

This article has been dead for over six months. Start a new discussion instead.