orphan objects

From: Tom (tom.cowdery_at_bigfoot.com)
Date: 11/26/03


Date: 26 Nov 2003 11:46:19 -0800

Suppose that you have code along the lines of what is shown below:

SomeObject x = new SomeObject();
SomeCollection coll = new SomeCollection(); //might be a Vector,
ArrayList, etc.
coll.add(x);
x = new SomeObject(); //occurs AFTER x is added to the collection

At this point, the object that was added to the collection is what I
mean by an orphan object. The reference 'x' no longer points to it,
but it isn't garbage either. It lives on as an anonymous object in
the Collection.

Obviously, coll.remove(x); won't work any more since x no longer
points to the original object.

Is there any way to identify which element is an orphan so it could be
removed from the Collection?