• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

GC

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The finalize() method is guaranteed to be called on any object to be GC�ed
True or False?
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic