The objects created in the String pool are not subjected to GC until the class is unloaded by the JVM. They get discarded at that time or just before the virtual machine unloads the class' bytecode.
Is that the reason why "str" in line 3 is not GCted?
I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
line 2 declares a primitive variable, not an object! And the question is "How many objects will be eligible .... Anyway "i" is put on the stack so it gets deleted as soon as is out of the scupe (function in this case). About String literals you already figured out the problem. Miki
Andres, I have never read such a definitive statement about garbage collection and the string literals. I am curious to know the source of that statement. Marlene