Can someone help...this used to be so easy in C++ and VB6 :)

I am dynamically creating multiple instances of a fairly simple class, tracking them via the Collections class in vb.net. I loop through the collection if I need to get to a particular instance to set some property, for example. Everything is fine, and works ok until I try to destroy the instances that I created (largely because I am probably not doing it right). What I am doing setting the instance to "nothing". That is, here is the portion of the code:

Dim node As mini_node
        ''destroy any existing defined nodes...
        For Each node In nodesCollection
            node = Nothing
        Next
        'clear the existing collection, if any.
        nodesCollection.Clear()

The problem is that I don't think the class instances are destroyed (I have a timer event enabled in some instances of the class and they continue to execute, even though I did the =Nothing already !!)

How do I destroy an instance of a class??? Please help a confused soul.

Thanks for any/all help in advance.

Oleg

Hi Oleg, difficult to know without further info, but I suspect you need to properly dispose of your nodes' timer objects. Perhaps you might try something like this:

Dim node As mini_node
        For Each node In nodesCollection
            node.Timer.Stop()
            node.Timer.Dispose()
        Next
        nodesCollection.Clear()

Alternatively have your class implement IDisposable (type "Implements IDisposable" towards the top of your class) and free up any resources explicitly during call to dispose. Then you need only have:

Dim node As mini_node
        For Each node In nodesCollection
            node.Dispose()
        Next
        nodesCollection.Clear()

Kind of a guess though:)

This article has been dead for over six months. Start a new discussion instead.