the literal "I'm here"
is a compile time constant string and as such gets placed in the constant string pool, which (up until java 7) was never garbage collected. that means sr
points to an object that will never be garbage collected.
r
, on the other hand, points to a copy of that string, which is not in any const pool and so is eligible for collection.
see the documentation for String.intern() for some more details on this string pool