Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Gc question

 
Rosemol Thanjappan
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am little bit confused about this question.
Please Help me.

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 your object's memory as soon as it becomes a candidate for garbage collection.
E. The garbage collector runs in low-memory situations.

My choices are :
A.false
B.false
C.false
D.false
E.true
Correct me if I am wrong.
Thanking you
Rosemol.
 
Rajiv Ranjan
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think only valid choice is c.
 
Rosemol Thanjappan
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi ,
Originally posted by Rajiv Ranjan:
I think only valid choice is c.

Option C. The garbage collector informs your object when it is about to be garbage collected.
How is garbage Collector informs ?

Thanking you
Rosemol.
 
Sam Zheng
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By calling the finalize() method of the object.
 
Vijayakumar Ramakrishnan
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I go for C,E.
C is done by giving a call the protected void finalize() throws Throwable method of the Object.
E is true coz gc is a low priority thread.
Vandanam,
Vijay
 
Ashish Agarwal
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only correct answer is c. Before collecting object's memoty gc invokes finalize().
Low priority thread does not mean that gc will run in low memory situations. You can never predict when gc is going to run, not even System.gc() ensures that.
Ashish
 
Rosemol Thanjappan
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all,
Now I chose only Option C.
Since low priority does not means low memory and Garbage Colletion cannot be predicted
Thanking you all
Rosemol.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic