I see many Q&A about Immutable String saying that JVM actually create a new reference when we do the following:
String text = "apple";
text = "orange"; // a new reference is created
My question is, what happen to the previous reference "apple"? Since Java Garbage Collection is automatic, does it means that there is no intentional way to re-claim the memory?
EDIT: The reason I am asking this question is that I would like to know how should I handle String variables in future.
Does String Literals get cleared by GC? If not, wouldn't the pool going to get so huge until a point where it goes out of memory? Considering if the program receives different string values from a textbox on the UI, each different values that the user enters are going to add on to the pool.