Hello everyone, i have a dougt regarding String and how garbage the collector works. for instance String created like this : String a = "Isto e um teste"; can be garbage collected ? if yes, does the garbage collector works with this Strings like any other object ? best regards Lu�s Filipe Meira
No, that String will never be garbage collected. The reason for this has to do with an optimization used by the JVM. This topic has been discussed many times before. Take a look at this thread for a great explanation. Corey
Luis - read through that thread that I pointed out. This turns out to be a more complicated issue than it seems at first glance. Strings aren't really "returned to a pool." Rather, there is a constant reference to them from a special table. Read the thread. It's good. Corey
Originally posted by Corey McGlone: Luis - read through that thread that I pointed out. This turns out to be a more complicated issue than it seems at first glance. Strings aren't really "returned to a pool." Rather, there is a constant reference to them from a special table. Read the thread. It's good. Corey
Thanks Corey pointing out the thread. Yeah, it is really good.
This information is not needed for the exam. String literals can be gc.ed if we download the class in which they were created. Doing that we download the constant pool of the class. This is the table that holds references to them. This is an example Go to the last program in the thread
SCJP2. Please Indent your code using UBB Code
We're all out of roofs. But we still have tiny ads:
Gift giving made easy with the permaculture playing cards