I've got a huge memory leak in my multi-threaded application that eventually crashes the program and bogs down the computer when it has exhausted my 1.5GB of RAM! I have about 15 threads running all at the same time. Each thread scans one of our subnets, for example, from 10.10.10.1 to 10.10.10.149 to find an active Win2k or WinXP computer. If it finds a computer it uses WMI to interface and pull a bunch of system and user data. Since WMI takes 60 seconds to timeout I ping each IP address before attempting to use WMI on it. I'm using a simple ping routine about 2250 times per cycle. Once a cycle finishes the thread sleeps for 5-7 minutes and starts again.
This is the ping routine code.
VB Code:
Private Function Ping(ByVal Computer As String) As Boolean Try If My.Computer.Network.Ping(Computer) Then Ping = True Else Ping = False End If Catch ex As Exception Ping = False End Try End Function
In trying to diagnose the problem I stumbled across this page and wonder if the problem would apply to my VB.NET program as well? I'm not experienced enough yet to understand all of the terminology, but can see that the Garbage Collector has trouble dealing with the ping functionality. So, a bunch of ping objects get built up in memory and are never released. I've tried calling the GC mulitple times throughout code, setting objects that are going out of scope to nothing, etc. I'm hoping someone can take a look and let me know what they think and if I'm affected.
http://blogs.msdn.com/joncole/archiv...15/505627.aspx
I'm testing my program now by completly removing the ping routine. After about an hour so far, the memory usage has barely moved... sitting right around 24MB. Granted it is going to take longer for there to be any evidence of a leak since the WMI timeout is ~120 times longer to return than a simple ping. I'm going to let it run overnight if possible and see what happens.




Reply With Quote