String hello = new String(new char[]{'H', 'e', 'l', 'l', 'o'});
hello.intern();
I understand that when new
operator is being used, hello
variable refers to a String
object on the heap.
In the next line, since it is interned, a new object is created in the String Pool, assuming "Hello" doesn't exist.
In such cases, is the String
object on the heap eligible for garbage collection?
I understand that String pool is part of the heap from Java 7 onwards.