Win a copy of Getting started with Java on the Raspberry Pi this week in the Raspberry Pi forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Liutauras Vilda
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Piet Souris

garbage collection's doubt

 
Rubel Ahammad
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.
 
Arvind Giri
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.
 
Surasak Leenapongpanit
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().
 
Please enjoy this holographic presentation of our apocalyptic dilemma right after this tiny ad:
Low Tech Laboratory
https://www.kickstarter.com/projects/paulwheaton/low-tech-0
reply
    Bookmark Topic Watch Topic
  • New Topic