Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...