dumb remove question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • news

    #1

    dumb remove question

    Well here's a sample of the code:

    class someobject{};
    ArrayList alist;

    alist = new ArrayList();

    for(int i = 0; i<10;++i)
    alist.Add(new someobject());




    OK now how do I get rid of the 10 objects in alist?

    Does Remove remove the object and delete it. Or does it just remeove it from
    the list?

    If it doesn't, how do I delete the objects?


    Thanks,
    Bill


  • Graeme Bradbury

    #2
    Re: dumb remove question

    ..Remove removes the object from the list.
    You don't need to delete the object, as long as you don't have any other
    references to that object the GC will get around to deleting it at some
    point.

    http://msdn.microsoft.com/msdnmag/issues/1100/gci/ is an intro to .Net and
    the GC


    "news" <wjfwjr@hotmail .comwrote in message
    news:qaWdnfDED-0gXpnanZ2dnUVZ_ hqdnZ2d@comcast .com...
    Well here's a sample of the code:
    >
    class someobject{};
    ArrayList alist;
    >
    alist = new ArrayList();
    >
    for(int i = 0; i<10;++i)
    alist.Add(new someobject());
    >
    >
    >
    >
    OK now how do I get rid of the 10 objects in alist?
    >
    Does Remove remove the object and delete it. Or does it just remeove it
    from the list?
    >
    If it doesn't, how do I delete the objects?
    >
    >
    Thanks,
    Bill
    >

    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: dumb remove question

      On Oct 4, 11:43 am, "news" <wjf...@hotmail .comwrote:
      Well here's a sample of the code:
      >
      class someobject{};
      ArrayList alist;
      >
      alist = new ArrayList();
      >
      for(int i = 0; i<10;++i)
      alist.Add(new someobject());
      >
      OK now how do I get rid of the 10 objects in alist?
      alist.Clear();
      Does Remove remove the object and delete it. Or does it just remeove it from
      the list?
      Just remove it from the list. Note that the object itself isn't in the
      list - just a reference to the object.
      If it doesn't, how do I delete the objects?
      Why do you want to delete the objects in the first place? That's what
      the garbage collector is for.

      Jon

      Comment

      Working...