disposal of object

P

patrick

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?
 
J

jkohen

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.
 
T

Thomas Kellerer

patrick, 20.12.2007 11:55:
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.

Yes, you need to remove it from the Vector
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top