That's pretty simple. The string appearing in the source code is interned, i.e., kept in a special pool, and there's no chance to collect it as it's referenced by the code of your method. It's needed when setName
gets called again, so it's obviously no garbage.
The situation with new String("name")
is very different as this creates a copy of the original String. Actually, there's no need to use this constructor since this change to String.substring
.
I guess the Eclipse Memory Analyzer doesn't show references contained in the bytecode (as nobody really needs it).