• 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
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

dout regarding garbage collection

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

 
Joel Salatin has signs on his property that say "Trespassers will be Impressed!" Impressive tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic