delete an instance of a class-VBForums
Results 1 to 4 of 4

Thread: delete an instance of a class

  1. #1

    Thread Starter
    Lively Member druid's Avatar
    Join Date
    Jun 2006
    Posts
    81

    delete an instance of a class

    hi everybody, for example a have a class and have created many instances of it, my question is how can i delete a certain instance of that particular class? can anybody point me in the right direction for me to solve my problem? thanks

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Candon City, Ilocos Sur, Phils.
    Posts
    10,810

    Re: delete an instance of a class

    How did you name the instances of your class?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    88,133

    Re: delete an instance of a class

    You don't. If you don't want to use that instance anymore then you simply remove all references to it, e.g. assign null to a variable that refers to it. If the object contains resources that need to be released then you would implement the IDisposable interface in your class and then you can call Dispose on that instance to release its resources. Beyond that, it's up to the .NET garbage collector when the actual memory the object occupies gets reclaimed.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Addicted Member
    Join Date
    Sep 2008
    Location
    Jacksonville, Florida
    Posts
    147

    Re: delete an instance of a class

    how you 'delete' it depends on how and where you are storing it and if it implements IDisposable. If the only thing holding a reference to it is a list then
    Code:
    list.Remove(item);
    . if it's a field then
    Code:
    field=null;
    if it implements IDisposable and is being used only in the scope of a single method and methods that method calls then use a using statement. If it's being used in the scope of a single method and you want to ensure no other code in that method can see that variable name, put that section in it's own scope block inside your method with
    Code:
    {var temporaryItem=new x; /* other method calls involving temporaryItem */ }
    Last edited by MaslowB; Nov 24th, 2009 at 08:55 AM. Reason: added extra code tags
    vb.net and C# in 2008 .net 3.5
    ImaginaryDevelopment blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.