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

From Boone's Exam Again

 
swati bannore
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Answer Given - b,c,e
I think,B is again not correctly worded...or is it..I hope,in real exam , wordings are more clear..
Comments--
Thanx
 
Dian He
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

my understanding b is not right.
you can call garbage collector whenever you like, but it can not be sure when it will actually run.
 
Vedhas Pitkar
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I think that only e is correct as u can't be sure whether the garbage collection will take place or not.
 
Bindesh Vijayan
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I think one can forcefully run the garbage collector by calling System.gc() method.In this way you force garbage collector to be called to reclaim the memory.If a forceful call is not done then the gc is called only when the JVM finds it is running low in memory,otherwise it will not call garbage collector and the memory will be reclaimed by the Operating System when the program ends.Although calling garbage collector is a waste of time.So I think b and e both are right and since I have no idea of any information being given to object by the gc, I'll stay quite.
If you want to see an example where you call gc and see the process of gc,then here is the code:-

One thing that I must add to the behavior of the program is that Iam not assigning it to any variable of A (see line#1) ,thus the objects created using new remains unreferenced thereby creating work for garbage collector.Had it been assigned to any object reference gc would'nt have work.I found it out lately.
This is what my understanding says,I may be wrong, so please correct me.
THANKS
[This message has been edited by Bindesh Vijayan (edited August 29, 2001).]
 
Jennifer Warren
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my understanding is that gc is a thread and one can not be sure when it is going to run even after the System.gc(); method.
correct me if i'm wrong.
thanx.
Jennifer
 
swati bannore
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I think ,c and e, are correct options.
Regarding b,Yes, we can call System.gc() but we can NOT guarantee that Garbage Collector will run..So the option.."You can run directlt Garbage Collector" Whenever you can" shd be false.
Regarding C, Objects gets notified before actual Garbage Collection...remember finalize() is called..
Hope it is correct...
Thanx
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic