when u try to instantiate a string object, it will initially search for a object in the pool with same value. if no object is found then it will create one for u and returns that object reference, if there is some object already in the pool, it will retur the reference of the same object.
so for the code u mentioned there are two reference variables pointing to one object.as, some reference is pointing to the object, no object is free, so no garbage collection.