Results 1 to 4 of 4
  1. #1

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

    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
    Candon City, Ilocos Sur, Phils.

    Re: delete an instance of a class

    How did you name the instances of your class?

    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
    Sydney, Australia

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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

    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
    . if it's a field then
    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
    {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


Click Here to Expand Forum to Full Width

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.