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

garbage collection!

 
ashok khetan
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
which of these options are true for the following question?(from Boone's Mock-exam).
Question 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.
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.
 
Roopa Bagur
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the answer is b. You can call the garbage collector by invoking system.gc() method.But there is no gaurantee that the objeects will be collected immediately because garbage collection is usually performed in low memory conditions
Originally posted by ashok khetan:
hi,
which of these options are true for the following question?(from Boone's Mock-exam).
Question 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.
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.

 
Mini Pilla
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it is c and e.
rajani
 
Bindesh Vijayan
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Rajani.Since if you look at option b more carefully,it will be clear that the option says about running GC which is no gurantee at all.Of course, you can call System.gc() but again, as Roopa mentions,it is a request rather than running it.
THANKS.
 
Roopa Bagur
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I really don't understand option c. Could you please explain it
Originally posted by Bindesh Vijayan:
I agree with Rajani.Since if you look at option b more carefully,it will be clear that the option says about running GC which is no gurantee at all.Of course, you can call System.gc() but again, as Roopa mentions,it is a [b]request rather than running it.
THANKS.[/B]

 
Bindesh Vijayan
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roopa,
Actually I think, what happens is when GC is to be done it calls finalize() on that particular object and this way it informs the object of being GC'd. You can view this phenomenon on the following code:

THANKS
 
Roopa Bagur
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bindesh. Good answer
Originally posted by Bindesh Vijayan:
[B]Roopa,
Actually I think, what happens is when GC is to be done it calls finalize() on that particular object and this way it informs the object of being GC'd. You can view this phenomenon on the following code:

THANKS[/B]

 
Roopa Bagur
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bindesh. Good answer
Originally posted by Bindesh Vijayan:
[B]Roopa,
Actually I think, what happens is when GC is to be done it calls finalize() on that particular object and this way it informs the object of being GC'd. You can view this phenomenon on the following code:

THANKS[/B]

 
Bindesh Vijayan
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roopa,
I would like to add here that, although the finalize is being called by Gc it's not Garbage Collection, still because it only does cleanup.And only when next time the finalize is callled the GC does the actual work on the object.This is what I studied in Thinking in Java, Bruce Eckel
Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic