This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
Hi , 1) If in finalize method we make re refrence to the object .Will that object ever be garbage collected. 2) Is it mandatory to call the base class finalize method in the subclass's finalize method else the compiler will give compile time error .
ms , welcome to javaranch. PROPER NAMES ARE NOW REQUIRED
Please Refer to the official naming policy of javaranch. You will have to reregister yourself with proper first & last name & help maintain the decorum of the forum. Waiting for your new posts with proper first & last name
1) If in finalize method we make re refrence to the object .Will that object ever be garbage collected.
No. since the gc calls the finalize method only once. If you make any reference to an object then it will not be GC'ed.
2) Is it mandatory to call the base class finalize method in the subclass's finalize method else the compiler will give compile time error .
Compiler won't give any error, but it's neccessory to call the superclass's finalize as finalize methods are not chained by default. I hope this is clear. Regards, Vadiraj. scjp
Regards<BR>---------<BR>vadiraj<P><BR>*****************<BR>There's a lot of I in J.<BR>*****************
Joined: Oct 18, 2000
Thanks a lot Vaidraj , Actually I read these two questions in one mock test and it was said that that first time the object will not be garbage collected but second time the GC will ignore finalize and the object will be garbage collected .I could not understand the logic .
Yes ms You it is true that finalize() will called only once on an object. If your creating a new Instance by using this() in finalize(),that means you r again creating the instance of this type but second time finalize() won't be called. And also if there is not any refrence which is pointing to the newely object created , it will be again grabage collected.So All the objects which r not represented by any variables are eligible for GC