rakesh kankavlikar wrote:SO if there is no reference how garbage collector calls the finalize method?
GC is a thread, so when it comes to know that there is no longer any valid reference referring to the object, he call its finalize() and freed the heap space occupied by that object. So the thing is, GC has some mechanism to access that object, may be storing its reference somewhere, like virtual pointer table but its just my wild guess
True, The point from David is very correct. Its the code that does not have the access to the object but the object will be still known and accessed by the jvm. Anyways its upto the jvm implementation and we need not have to worry much about it. What we need to know is we should not perform cleanup tasks inside the finalize method. For more reference on evils of finalize method please read Effective Java from Joshua Bloch.
Thanks and Regards, Pradeep Kumar
SCJP 1.6, SCWCD 5.0
Opportunity is missed by most people because it is dressed in overalls and looks like work - Edison. Tiny ad:
a bit of art, as a gift, the permaculture playing cards