Re: memory leak using system.windows.forms.timer

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Feb 11, 3:37 pm, Tom Shelton <tom_shel...@xxxxxxxxxxxxxxxxxx>
wrote:
On 2009-02-11, Gestalt <sspenn...@xxxxxxxxx> wrote:



On Feb 11, 1:43 pm, Tom Shelton <tom_shel...@xxxxxxxxxxxxxxxxxx>
wrote:
On 2009-02-11, Gestalt <sspenn...@xxxxxxxxx> wrote:

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).

Can anyone think of a reason why this would be causing a problem?

Repost the question to the vb.net group:

microsoft.public.dotnet.langauges.vb

And when you do - post the code to your CounADComputers method.  This is
obviously where the issue most likely is.  You are keeping a reference to
something around that you shouldn't be.

--
Tom Shelton

Thanks for the advice, I'll repost in the other forum.

And for the record, I indicated that the problem occurs even if I
remove the reverence to the CountADComputers subroutine and replace it
with a static integer.  I believe that would make it less likely to be
the "obvious" source of the issue.

Ah..  sorry... i misread that :)

--
Tom Shelton

It is I who should be sorry. You were indeed correct about the source
of the memory leak. I later discovered that my Visual Studio install
was not consistently generating new builds on demand so when I thought
I was testing the app with the subroutine commented out, it was in
fact still very much active.

Using Ants Profiler I have discovered that the AD search is actually
accumulating all of its results in memory and never releasing them.
Right now researching Application Domains as it has been suggested
that by putting my leaky process into a separate application domain I
can then dismiss it when done and the system should then be forced to
clear the unwanted data from memory.

I apologize for my snappish response earlier.
.



Relevant Pages

  • Re: memory leak using system.windows.forms.timer
    ... the tick event fire a function that returns the number of workstation ... subroutine, memory leaks. ... subroutine with a static number I still leak memory. ...
    (microsoft.public.vb.general.discussion)
  • Re: memory leak using system.windows.forms.timer
    ... the tick event fire a function that returns the number of workstation ... subroutine, memory leaks. ... subroutine with a static number I still leak memory. ...
    (microsoft.public.vb.general.discussion)
  • Re: Memory Leak detection with HeapAlloc ... ?
    ... Your code won't detect memory leaks from HeapAlloc because it checks only those allocations taht were made via CRT. ... anyone knows of a solution where one could enable a page heap as described in the articles from sourcecode? ...
    (microsoft.public.vc.language)
  • Re: Mix of "functional" and "procedurial" programming
    ... Passing a raw machine address to a subroutine, ... You can have the *convention* that a specific amount of memory ... or the CAR is the software-understadable error code and the CDR is ...
    (comp.programming)
  • Re: Memory Leaks?
    ... > not relinquish all memory back to the available pool for XP to use. ... To flesh this out a bit, memory leaks are a far greater problem in scripts ... When a script terminates, WSH runs a cleanup process that deletes the ... An object will be disconnected only after all references to it ...
    (microsoft.public.windowsxp.general)