Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

dout regarding garbage collection

 
nagaraj raja
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai ,

Here i am thinking answer is c is it right plz explain?

 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But you know what, I think combining String Objects and a question about Garbage Collection together is just mean. It ends up asking about two seperate things.

1. Garbage Collection
2. Which Strings are in the String Pool and which are Objects on the heap.

Mark
 
Rubens Gomes
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
b) 1 --> "Nick" is the only object which does not have a stack variable reference pointing to it. The other Strings have references to them.
 
Shivani Chandna
Ranch Hand
Posts: 380
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

String name;
String newName = "Nick";
newName = "Jason";
name = "Frieda";
String newestName = name;
name = null;
//Line A


I think it should be 2 ....
name and "Nick" string object lost

am i wrong?
 
Arvind Giri
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think

< (b) 1 > is correct.

As there were only 3 objects and 2 are being referenced.
So its "NICK" which is eligible for garbage collection.
further u can't take name as object its only reference variable.
 
Shivani Chandna
Ranch Hand
Posts: 380
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Arvind Giri:
[QBfurther u can't take name as object its only reference variable.[/QB]


Right if newestName didnt refer to the object refer by name then doing name=null wd make 2 objects elegible for GC. Thanks !
 
Steve Sugden
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For what its worth, I agree with Rubens and Arvind. "Nick" appears to be the only String object not referenced.

Are we right? Can I have my certificate now?

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic