Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Another question on GC

 
sajida kal
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q65 from Barry Boones mock exam.
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.
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.
Correct answers according to the mock are b,c,e.
I have a few questions here-
b. This seemed to be an incorrect option to me. GC can be invoked anytime by a program, but whether it runs or not, is entirely upto the JVM. So why is b a correct answer.
c. I read somewhere that the finalize method is called for an
object only once. If, in the finalize method, we 'revive' the reference again, then if gc is invoked a second time, the finalize method will not be called. If the above is true, then c does not seem to be a valid option.

Would appreciate if anyone could comment on this.
Thanks
Sajida
 
Sharmila Abkari
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
option (b) is correct because
u can call the method System.gc() to run garbage collector at any point you choose, but that doesn't mean you will get it.
 
Sharmila Abkari
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
option (c) is correct because
The gc will usually call an object's finalize() method just before the object is gc-ed .
And any object is garbage collected only once.
Please correct me if i am wrong.
 
nitin sharma
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello experts,
Put some more light on option b.Tell us it's correct or not.
 
Sharmila Abkari
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by nitin sharma:
Hello experts,
Put some more light on option b.Tell us it's correct or not.


Nitin,
I am no expert , but i found the same q's in a old quote: Topic: Gc question
posted December 25, 2000 07:45 PM
and
Topic: garbage collection
posted December 26, 2000 10:13 PM
this has lot of discussion on this topic.
u can search for it.
Regards
Sharmila

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic