Hi Ranchers I got a doubt in the question given below. Question : If the finalize() method of an object is re-references an object so that it becomes in-eligible for garbage collection
1.The compiler will throw an error. 2.The garbage collector "collects" the object anyway. 3.The garbage collector does not collect the object in the present sweep. But when the object becomes eligible for garbage collection again, its finalize method will not be called by the garbage collector (i.e., if the garbage collector gets a chance to run.). It will simply be garbage collected. 4.The object can never be garbage collected and hence leads to memory-leak. Each time the garbage collector calls finalize before "collecting" the object the object "resurrects" itself.
To me i thinks it's option-4 but actual answer is given option-3 , is grabage collector behave like that way in those situations.
If you go through the Java Docs for finalize() you will find explanation for the answer being (c).
After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.
The finalize method is never invoked more than once by a Java virtual machine for any given object.
The exact same information as the above listing is to be found in class Object's finalize method API documentation. So there is no need to go to the extent of getting the source code in this case - especially because it is more readable in the API.