• 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

GC

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://www.javaprepare.com/notes/classes.html
see this site
last q says that string literal is eligible for garbage collection
public class GCTest {
public static void main(String args[]) {
String a,b;
String c = "test";
a = c;
c = null; // The String "test" is not yet
//available for GC as a still points to "test"
b = new String("xyz");
b = c; // String "xyz" is now available for GC.
a = null; //String "test" is now available for GC.
}
}
a = null; //String "test" is now available for GC.
I think string literal are not garbage collected
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not totally sure that I understand your question, but its not saying that it IS garbage collected. Its stating that it is ELIGIBLE. Garbage collection can not be forced nor predicted.
Hope this helps a little,
Travis B.
 
Ana P
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thx this does help.
I just wnat to make sure that string literals are not garbage collected
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ana P:
Thx this does help.
I just wnat to make sure that string literals are not garbage collected


You're right, the answer given is incorrect. String literals are never garbage collected as there is always a reference to them from the constant table. Check out this thread for a good discussion on the topic.
Corey
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Ana P"
Welcome to the JavaRanch! Please adjust your displayed named to match the JavaRanch Naming Policy.
You can adjust it here.
Thanks! and welcome to the JavaRanch!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic