vb.net multithreads memory leak

doctaconsulting

New member
Joined
Jul 13, 2005
Messages
1
Programming Experience
Beginner
Please help !! This memory leak is getting crazy.

My applications supposed to create 150 threads and after 30 minutes, I need to kill them and start over witn 150 new threads. Overtime the application keeps consuming the existing memory and it crashes.

This is the class that generates the memory leak.

visual basic code:--------------------------------------------------------------------------------

Imports System.Threading.Thread
Imports System.Threading.ThreadState


Public Class clsTest

Private MyThread As System.Threading.Thread
Public id As Long


Public Sub New()
MyThread = New System.Threading.Thread(AddressOf execute)
End Sub

Public Sub execute()
'do nothing
End Sub

Public Sub startTest()
If MyThread.ThreadState = Unstarted Then
MyThread.Start()
Else
MyThread.Resume()
End If
End Sub

Public Sub stopTest()
If MyThread.ThreadState = Running Then
MyThread.Suspend()
End If
If MyThread.ThreadState = WaitSleepJoin Then
MyThread.Interrupt()
End If
End Sub

Public Sub abortTest()
stopTest()
If MyThread.IsAlive = True Then
MyThread.Abort()
End If
End Sub

Public Sub dispose()
abortTest()
MyThread = Nothing
End Sub


End Class


--------------------------------------------------------------------------------



this is how I test it.

Code:

counter = 0
While counter < 150000
counter = counter + 1
Dim auxNode As New clsTest()
auxNode.id = counter
auxNode.dispose()
auxNode = Nothing
End While

System.GC.Collect()


I use the Task Manager to measure memory utilization.

From a form I call a loop whick creates 150000 instances and then kill objects by calling the dispose() method.
I do see how the GC doesn't release the allocated resources.

Why ? !!!!! *$&#@!)($^@!($!

Is there anything wrong with my code ?

Thanks in advanced for your time and assistance !!
I really appreciated it.
 
Back
Top