• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Eligibility for Garbage Collection

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How many strings are eligible to be garbage collected after the execution of line 2 and line 4?
public class TestClass
{
public static void main(String args[ ] )
{
String str0 = null;
String str1 = "some string";
String str2 = "second string";
String str3 = "Third string";
str0 = str1; // 1
str1 = null; //2
str2 = str0; //3
str3 = str2; // 4
}
}
Could someone pls explain me this in detail... .I had a notion that once u assigna object reference to a different reference, the first reference doesnt exists no more. (str0 = "a"; str1 = "b"; str1 = str0) I thought (or rather I think) reference str0 is lost after this... someone pls help me.
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This type of quest were discussed before as well pls refer the following url
http://www.javaranch.com/ubb/Forum24/HTML/000126.html
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic