Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage Collection Question

 
Fes D Gaur
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got this question from Bary Boon's mock exam.

Q 65. Which statements about Garbage Collection are true?

Select all valid answers:
a. You can directly free the memory allocated by an object.
b. You can directly run the garbage collector whenever you want to and it will be schedule in due time..
c. The garbage collector informs your object when it is about to be garbage collected.
d. The garbage collector reclaims an object´┐Żs memory as soon as it becomes a candidate for garbage collection.
e. The garbage collector runs in low-memory situations.

The answer given is b,c,e.

The exam was created before JVM 1.4. So I'm pretty sure that b is not correct. I think e is correct. How about c?

Thanks,
Fes
 
Lakshmanan Arunachalam
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C is correct. GC will inform the objects when it goes to collect the objects, by calling finalize method on them.
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java specifications make the following promise about finalize() method:

Before reclaiming the memory occupied by an object that has a finalize() method, the garbage collector will invoke that object's finalize() method.
 
Naresh Gunda
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

-->The System.gc() method can be used to request garbage collection,
-->Although Java provides facilities to invoke the garbage collection, explicitly, there are no guarantees that it will be run. The program can only request that garbage collection be performed, but there is no way that garbage collection can be forced.

Above two statements says option 'b' is wrong know.
friends, pls correct me if i am wrong.

Thanx & Regards
Naresh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic