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

MIndQ #36

 
mary lee
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
look at this question:
36. How many objects are eligible for garbage collection once execution has reached the line labeled Line A?
String name;
String newName = "Nick";
newName = "Jason";
name = "Frieda";
String newestName = name;
name = null;
//Line A
the answer is 1
but I think should be 2, there are three String objects "Nick"
"Jason" and "Frieda", at line A only "Frieda" is still referrenced by newestName , other two are not referrenced any more
is it right?
could anyone help? the garbage collection always make me confused
 
Mahajan Bhupendra
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi mary
i think ur right ..
2 must be correct ans
always draw diagrams whenever the object is created
and one box for a variable and make it point to
respectove obj..
so u wouldn't get confused..
i also got confused in Exam and missed the question.
Bhupendra
 
g krishnan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
guys,
i had drawn the diagram and found only "Nick" is not pointed by any of the references, so i think 1 is correct
thanx
 
Vidya Krishnamurthy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the right answer is 1. the only object that is eligible for garbage collection is "Nick". "Jason" is referred by new name at line A.
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jason is referenced by newName
Frieda is referenced by newestName
Nick isn't referenced at all
So only 1 object is eligible
Hope that helps,
Bill
 
Mahajan Bhupendra
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wait a min
<pre>
Nick Jason Frieda
newName - -
- newName -
- newName name
- - name,newName
- - newName
</pre>
so i thoink 2 is correct ans
Bhupendra
[This message has been edited by Mahajan Bhupendra (edited April 03, 2001).]
 
Chris Cingrani
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mahajan -
Bill is correct, as Nick is the only object without a reference. In your diagram you are pointing "Frieda" to newName, when it should be pointing to newestName.
Hope that helps -
Chris

[This message has been edited by Chris Cingrani (edited April 03, 2001).]
 
Mahajan Bhupendra
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris
Soory i m very soory..
i got confused between newName and newestName..
1 is correct ans..
soory to all
Bhupendra

[This message has been edited by Mahajan Bhupendra (edited April 04, 2001).]
 
mary lee
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes
I did not notice the newname and newestname are different
a careless mistake
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic