• 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 question.

 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following is a question from MindQ's mock exam.
37. 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.
I thougth only a) is correct. But the answer given is a b and c. Would anyone explain it to me.
Thanks in advance.
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
a) The garbage collector can be invoked explicitly using a Runtime object.
The garbage collector might be delayed by a higher priority thread, or run only in low memory situations. Thus the program might end before the g.c. gets a chance to run.
b) The finalize method is always called before an object is garbage collected.
True, if the object is garbage collected, its finalize method has been called exactly once.
c) Any class that includes a finalize method should invoke its superclass' finalize method.
I disagree. An instance of Object should not do so. Neither a class whose base class had not declared a finalize method.
However, finalization of objects is not a chained process as construction is. That is, finalize does not automatically calls the finalize method of the base class. For a proper finalization, the last sentence in a finalize method should be "super.finalize()", as long as such method exists. It must be the last one because during the execution of a given finalize method some resources in the base class might be needed to be available. When the finalization is done, they are released via the call to super.finalize();
 
Yuan Ye
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jose from what i know a) is incorrect becos u cannot force the garbage collector.
as for c) even i am unsure. someone pls clarify
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic