I'm curious how values from a string-pool get removed?
suppose:
String a = "ABC"; // has a reference of string-pool
String b = new String("ABC"); // has a heap reference
b = null;
a = null;
In case of GC, "ABC" from the heap gets collected but "ABC" is still in the pool (because its in permGen and GC would not affect it).
If we keep adding values like:
String c = "ABC"; // pointing to 'ABC' in the pool.
for(int i=0; i< 10000; i++) {
c = ""+i;
// each iteration adds a new value in the pool. Previous values don't have a pointer.
}
What I want to know is:
- Will the pool remove values that are not referred to? If not, it means that the pool is eating up unnecessary memory.
- What is the point then because the JVM is using the pool?
- When could this be a performance risk?