G
Gestalt
I'm working on a small application using the
system.windows.forms.timer. The intent is to set an interval and on
the tick event fire a function that returns the number of workstation
objects that reside in a specific OU in Active Directory.
On the surface the application runs great. Under the surface, it's a
different story. I've found that every time the tick calls a trivial
subroutine, memory leaks. I've tried summoning garbage collection
periodically but that has not resulted in any improvement in memory
consumption. Left overnight the app will bloat to over half a gig of
RAM consumed (and continuing to climb). I have tested it on XP Pro,
Vista SP1 (x64) and Windows Server 2008 (x86).
The subroutine that appears to be leaking is here as follows:
Private Sub CheckComputers()
Dim intCount As Integer
intCount = CountADComputers(My.Settings.strTargetDN)
If intCount > My.Settings.intTargetCount Then
intTrigger = 1
Else
intTrigger = 0
End If
intCount = Nothing
End Sub
I have found that if I substitute the call to the CountADComputers
subroutine with a static number (e.g. 1) I still leak memory. If I
leave this subroutine out of the program then the leak stops (and
obviously the program does nothing).
For the record, here is the CountADComputers subroutine:
Public Function CountADComputers(ByVal strADPath As String) As
Integer
Dim intCount As Integer
Dim entry As New DirectoryServices.DirectoryEntry(strADPath)
Dim mySearcher As New
System.DirectoryServices.DirectorySearcher(entry)
mySearcher.PageSize = 1000
mySearcher.Filter = "(objectClass=Computer)"
intCount = mySearcher.FindAll.Count
mySearcher.Dispose()
mySearcher = Nothing
entry.Dispose()
entry = Nothing
Return intCount
End Function
Can anyone think of a reason why this would be causing a problem?
system.windows.forms.timer. The intent is to set an interval and on
the tick event fire a function that returns the number of workstation
objects that reside in a specific OU in Active Directory.
On the surface the application runs great. Under the surface, it's a
different story. I've found that every time the tick calls a trivial
subroutine, memory leaks. I've tried summoning garbage collection
periodically but that has not resulted in any improvement in memory
consumption. Left overnight the app will bloat to over half a gig of
RAM consumed (and continuing to climb). I have tested it on XP Pro,
Vista SP1 (x64) and Windows Server 2008 (x86).
The subroutine that appears to be leaking is here as follows:
Private Sub CheckComputers()
Dim intCount As Integer
intCount = CountADComputers(My.Settings.strTargetDN)
If intCount > My.Settings.intTargetCount Then
intTrigger = 1
Else
intTrigger = 0
End If
intCount = Nothing
End Sub
I have found that if I substitute the call to the CountADComputers
subroutine with a static number (e.g. 1) I still leak memory. If I
leave this subroutine out of the program then the leak stops (and
obviously the program does nothing).
For the record, here is the CountADComputers subroutine:
Public Function CountADComputers(ByVal strADPath As String) As
Integer
Dim intCount As Integer
Dim entry As New DirectoryServices.DirectoryEntry(strADPath)
Dim mySearcher As New
System.DirectoryServices.DirectorySearcher(entry)
mySearcher.PageSize = 1000
mySearcher.Filter = "(objectClass=Computer)"
intCount = mySearcher.FindAll.Count
mySearcher.Dispose()
mySearcher = Nothing
entry.Dispose()
entry = Nothing
Return intCount
End Function
Can anyone think of a reason why this would be causing a problem?