What happens to the object if I reassign its reference variable to another object? How does Java manage this object which does not have any reference variable now?
Objects exist on Heap of the memory, I tried but could not find how Java manages such "dangling" objects as described below.
class Box{...}
...
Box b1 = new Box(); //Instance 1
Box b2 = new Box(); //Instance 2
b1 = b2;
....
Here as you can see Instance 1 has lost its reference variable. What happens to this object? How Java/JVM manages such scenarios if in case it occurs?