• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

garbage collection's doubt

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
MindQ's

Which of the following statements about Java's garbage collection are true?

a) The garbage collector can be invoked explicitly using a Runtime object.
b) The finalize method is always called before an object is garbage collected.
c) Any class that includes a finalize method should invoke its superclass' finalize method.
d) Garbage collection behavior is very predictable.

ans given: a,b,c.

But,
a: we only can request garbage collector using Runtime Object.
b: K&B says that , you can't count on the garbage collector to ever delete an object. So Any Code that you put into your class's overriden finalize() method is not guaranteed to run.

I think only correct answer is c.
coz:
Kalid Mugal's SCJP1.2 Says(Page 253) "Finalizers are not implicitly chained like constructors for subclasses, therefore a finalizer in a subclass should explicitly call the finalizer in its superclass as its last action.
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
.
Dear Rubel,
The 2nd option can be taken in other words as "before an object is garbage collected, the finalize method is always called". now it seems ok.

and about 1st option he is saying only abt invoking. which doesn't mean sure excution. explicitly invoking is like making request.
 
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Option a) can be called by System.gc() or Runtime.gc().
 
Squanch that. And squanch this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic