• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

garbage collection question.

 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Thanks
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • 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
 
Why am I so drawn to cherry pie? I can't seem to stop. Save me tiny ad!
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!