Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

garbage collector......output.....?

 
Ganeshkumar cheekati
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is from esnips


Given the following code, how many objects will be eligible for garbage collection on the line with the comment //here

answer is:no object is eligible.

here two objects created for x and y.changes in method will not modify these objects.so up to now no object is eligible.

In line1 z is pointing to the object which is refered by y.
In line2 z is unreferenced.so one object is eligible.

can you explain line1 and line2?
[ November 02, 2008: Message edited by: Ganeshkumar cheekati ]
 
Vijitha Kumara
Bartender
Pie
Posts: 3918
10
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


It's the reference you are making null. What about the y reference? Still the object (created with the value 99) is referenced by y.
[ November 02, 2008: Message edited by: Vijitha Kumara ]
 
Anoobkumar Padmanabhan
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi



In line1, we are doing is that, just giving a new refenrce, z, to the object referred by y. so both y and z are pointing to the same object. In line2, we are assigning the refernce, z to null. ie, only changing the refernce, z. Still, y is pointing to the object. So, this won't be available for garbage collection. So the answer will be right.
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I have changed the code a little bit. When you set yy to null, it has no effect on y. So y refers to the integer object with value 99 and x refers to integer object with value 10 when the statement in question is reached.
 
Ganeshkumar cheekati
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah i got it .
 
Henry Wong
author
Marshal
Pie
Posts: 21504
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is from esnips


The site being quoted is a filesharing site -- and cannot be used to validate a source. Filesharing sites do not check validity -- in fact, it has been know to share copyrighted materials.

Please do not quote from this site again -- as it will be treated as without a quote, and may have to be removed.

Henry
[ November 03, 2008: Message edited by: Henry Wong ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic