This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GC

 
Siva Sivaraman
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The finalize() method is guaranteed to be called on any object to be GC�ed
True or False?
 
John Paverd
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Siva Sivaraman:
The finalize() method is guaranteed to be called on any object to be GC�ed
True or False?

True. From the JLS, section 12.6:
Before the storage for an object is reclaimed by the garbage collector, the Java virtual machine will invoke the finalizer of that object.
However, a particular object may never be garbage collected, so its finalize() may never be called.
 
david eberhardt
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Siva Sivaraman:
The finalize() method is guaranteed to be called on any object to be GC�ed
True or False?

I'd say True -
this question is a little tricky ...
we know that actual garbage collection is never guaranteed when we make calls such as "Runtime.getRuntime.gc() or System.gc() however,
According to the book "Mike Meyer's Certification Passport Java 2" written by Glass,Griscti, Isayeva, Kallambella, Sierra
(pg.129) "Every object inherits a finalize() method from java.lang.Object class.
The garbage collector is garunteed to invoke this method once prior to reclaiming the object's memory"

And another book "Java 2 Sun Certified Programmer Study Guide" 2nd Edition from Osborne states:
"Every class has a special method called a finalizer that is called just before an object is collected. The JVM calls the finalizer for you as appropriate; you never call a finalizer directly."
 
Siva Sivaraman
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to you all.
Didn't want to be trapped with such tricky questions.
The finalize() method is guaranteed to be called on any object eligible for GC.
True or False?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic