An object has been added into a Vector v:
v.add(obj);
Later I want to dispose of the object.
Must it first be removed from the v for garbage disposal
to get rid of it.
Or would setting obj=null; be enough to dispose of it?
jkohen@gmail.com - 20 Dec 2007 11:23 GMT
The instance won't get disposed until you release all its references.
If obj is local to a function and the thread has left the function,
then that reference is gone and you don't need to set it to null
explicitly. If obj happens to be a static field and you cannot reduce
its scope, then you might want to set it to null, or it will be alive
for as long as the class itself is referenced.
patrick - 20 Dec 2007 11:36 GMT
thats clear.
thanks
patrick
> The instance won't get disposed until you release all its references.
>
[quoted text clipped - 3 lines]
> its scope, then you might want to set it to null, or it will be alive
> for as long as the class itself is referenced.
Thomas Kellerer - 20 Dec 2007 11:37 GMT
patrick, 20.12.2007 11:55:
> An object has been added into a Vector v:
> v.add(obj);
[quoted text clipped - 3 lines]
> Must it first be removed from the v for garbage disposal
> to get rid of it.
Yes, you need to remove it from the Vector