disposal of object

Discussion in 'Java' started by patrick, Dec 20, 2007.

  1. patrick

    patrick Guest

    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?
     
    patrick, Dec 20, 2007
    #1
    1. Advertising

  2. patrick

    Guest

    Re: disposal of object

    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.
     
    , Dec 20, 2007
    #2
    1. Advertising

  3. patrick

    patrick Guest

    Re: disposal of object

    thats clear.
    thanks
    patrick

    <> wrote in message
    news:...
    > 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, Dec 20, 2007
    #3
  4. 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
     
    Thomas Kellerer, Dec 20, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cameron

    DirectoryEntry Disposal Test

    cameron, Apr 13, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    520
    Willy Denoyette [MVP]
    Apr 14, 2004
  2. Roger Twomey
    Replies:
    3
    Views:
    762
    Chris R. Timmons
    Feb 18, 2005
  3. TCORDON

    DataSet Disposal

    TCORDON, Mar 22, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    2,607
    JiangZemin
    Mar 23, 2005
  4. ASP.NET Object Disposal

    , Aug 20, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    425
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Aug 21, 2006
  5. Amadrias

    Session object correct disposal

    Amadrias, May 3, 2006, in forum: ASP .Net Security
    Replies:
    0
    Views:
    111
    Amadrias
    May 3, 2006
Loading...

Share This Page