Hi,
if the object has no references from any live
thread,then it is eligible for the garbage collection.
when
anObj = anObj.toUpperCase();
is executed a new
string object will be created and the reference anObj is pointing to it.But the old string doesn't have any references assigned to it. so it is eligible for garbage collection.