• 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
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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().
 
I carry this gun in case a vending machine doesn't give me my fritos. This gun and this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic