doctaconsulting Posted July 13, 2005 Posted July 13, 2005 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. Quote
Administrators PlausiblyDamp Posted July 13, 2005 Administrators Posted July 13, 2005 I notice you do not appear to be calling the MyThread.Start anywhere in your code - if you never start it all the code you have checking the ThreadState will never be true as it's state will always be Unstarted. As a side effect this means the .Abort will never get called either. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.