File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GC (javaprepare.com)

 
Cathy Song
Ranch Hand
Posts: 270
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Which of the following statements related to Garbage Collection are correct. Select the two correct answers.
a. It is possible for a program to free memory at a given time.
b. Garbage Collection feature of Java ensures that the program never runs out of memory.
c. It is possible for a program to make an object available for Garbage Collection.
d. The finalize method of an object is invoked before garbage collection is performed on the object.

The answer given is c,d.
I have a question regarding d.
"The finalize method is never invoked more than once by a Java virtual machine for any given object." According to this statement option d is incomplete. Or may be I do not understand what the above statement means..
Any thoughts? Thanks.
 
Vad Fogel
Ranch Hand
Posts: 504
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oblect class API:

The general contract of finalize is that it is invoked if and when the JavaTM virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized.
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are correct, Cathy. If finalize runs but the object is not gc'ed then finalize will not run later when the object is gc'ed. But "d" is correct too. Before an object is gc'ed, finalize will run. The object can not be gc'ed unless finalize has run. It may be that finalize ran long before the object was gc'ed but the question doesn't state "immediately" before garbage collection.
 
Cathy Song
Ranch Hand
Posts: 270
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

It may be that finalize ran long before the object was gc'ed but the question doesn't state "immediately" before garbage collection.

I see your point Thomas.
Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic