public class Test
public Shared Sub Main
Dim col As New Collection()
Dim obj As Class1
For x As Integer = 1 To 100
obj = New Class1(col)
Next x
Console.WriteLine("Collection contains " + col.Count.ToString() + " objects")
col = Nothing
obj = Nothing
GC.Collect()
GC.WaitForPendingFinalizers()
End Sub
End class
Public Class Class1
Shared m_classcount As Integer
Dim m_ClassId As Integer
Dim m_Collection As Collection
Public Sub New(ByVal mycontainer As Collection)
MyBase.New()
mycontainer.Add(Me)
m_Collection = mycontainer
m_ClassId = m_classcount
m_classcount = m_classcount + 1
End Sub
Protected Overrides Sub Finalize()
System.Diagnostics.Debug.WriteLine("Destructed " & m_ClassId.ToString())
End Sub
End Class
|