Win a copy of Microservices in Action this week in the Web Services forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

dout regarding garbage collection  RSS feed

 
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?

 
ranger
Posts: 17314
11
IntelliJ IDE Mac Spring
 
Mark Spritzler
ranger
Posts: 17314
11
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
 
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.
 
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?
 
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 !
 
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?

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!