This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt in finalize() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt in finalize()" Watch "doubt in finalize()" New topic
Author

doubt in finalize()

Vidhya Ramaswamy
Ranch Hand

Joined: Oct 10, 2007
Posts: 65
Taken from MasterExam:

I thought that finalize() can only be called once for an object, and since the program is already calling finalize(), gc will not call it.
Please explain.
Harvinder Thakur
Ranch Hand

Joined: Jun 10, 2008
Posts: 231
The finalize method is never invoked more than once by a Java virtual machine for any given object. In for loop you are yourself invoking the finalize method programmatically and not the JVM automatically ( which is done when objects are GCed).

Moreover, the finalize method is not guaranteed to be called by the GC. The only guarantee is that if called once by JVM it won't be called again by JVM at the time of garbage collection.
[ December 14, 2008: Message edited by: Harvinder Thakur ]

thanks
Harvinder
Vidhya Ramaswamy
Ranch Hand

Joined: Oct 10, 2007
Posts: 65
Thanks, Harvinder.
I thought that finalize() can be invoked only once for an object(program or JVM).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubt in finalize()
 
Similar Threads
finalize() method.
Garbage collection
priority of garbage collector thread
GC
Garbage Collection ..finalize()..?