paparush
paparush

Reputation: 1348

Windows Forms App Timer Memory Leak?

I have a very simple Windows Forms application written in c# that fires a timer every 30 seconds to check to see if a particular process is running.

private void timer1_Tick(object sender, EventArgs e)
{
    Process[] localByName = Process.GetProcessesByName("ahost");

    if (localByName.Length > 0)
    {
        //the process is running...do nothing
    }
    else
    {
        //send me an email
        timer1.Enabled = false;
    }
}

Since the process it's looking for is basically always running, I'm not hitting the email code in the else at all.

Here's the memory usage:

Startup         3,580
Startup +1min   3,724
Startup +10min  7,484
Startup +30min  8,024
Startup +60min  7,604

Am I to assume that the GC is doing it's job because the app only doubled it's memory footprint in an hour?

Is this standard GC behavior?

My little EXE was written in VS2010 against .NET Framework 3.0 and is running on a Win2008 R2 server.

Upvotes: 1

Views: 1206

Answers (1)

Jeremy Thompson
Jeremy Thompson

Reputation: 65554

No, there is no memory leak, that is the expected behavior of a program in a langauge that uses a garbage collector. The memory will increase until eventually it hits a point where the Garbage Collector cleans up any unneeded objects.

Unless you are working with COM objects, Graphics, Bitmaps, Fonts, basically any unmanaged resources that may need disposing, then its not leaking.

Have you got a plan B if your app crashes? You might want to consider using the server's in built functions to do this. You can figure out when an application terminates by configuring audit process tracking in Windows. The following links might get you started:

Audit process tracking

How can I track what programs come and go on my machine?

The process tracking will create entries in the Windows event log which you can then use to send the email.

Send an email when an event is logged

Upvotes: 2

Related Questions