Stephan van Hulst wrote:
Sunny Bhandari wrote:I had read that once finalize has been invoked then the object is guaranteed to be garbage collected. Seems like the above code will not achieve the desired result. Please verify...
Have you tried running the code? What are your conclusions?
Ikpefua wrote:
Sunny Bhandari, I read something COMPLETELY different from what you read and my reference is Chapter 3, Page 263 of the K & B Book, please READ CAREFULLY:
______________________________________________________________________________________
There are a couple of concepts about the finalize() that you need to remember.
-For any given object, finalize() will be called ONLY once (at most) by the garbage collector
-Calling finalize() can actually result in SAVING an object from deletion
______________________________________________________________________________________
I actually ran the code that Stephan posted here and it gave me the following result:
Garbage collector is trying to collect me
Garbage collector failed
This perfectly comfirms the K & B book
______________________________________________________________________________________
I will appreciate it if you can quote your source, this will help us a lot, another 'possible occurence' is that you
misread your source's explanation, no one will blame you for misreading since that usually happens to everybody.
Thank you for your understanding.