Possible memory leak in VB.NET application with Timer

Hi All,

I wonder if someone can have a look at my code and tell me if there is a possible memory leak.  You can download the VS 2003 project from here: ftp://accdata1.eurosql.com/ReplicationStatus.zip

Basically, when the app is started it uses approx 1.6MB of memory, during a short period, say about 10 minutes, the useage seems to settle around 25MB!

A little background on what the app does...

The application is a taskbar app and has a very small windows form, which when opened, shows the status of a clients SQL Server pull subscription.  The taskbar icon has different states depending on the status of the pull subscription, which is updated every 5 seconds.  The status on the windows form itself is not updated, until the user selects to show the windows form.

Below is the timer code which fires-off this status update request.  If I disabled this timer, the app memory stays at 1.6MB, so obviously it's what the sub CheckClientStatus() is doing that is the problem, but I haven't managed to work out what that is.

Have a look at the ReplStatus.vb form and code and look for the following timer and below this the culprit sub CheckClientStatus()

  Private Sub myTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles myTimer.Tick
    myTimer.Interval = CInt(RefreshInterval.Text) * 1000
    myTimer.Enabled = False
    CheckClientStatus()
    myTimer.Enabled = True
  End Sub

I'm sure this is a clean-up problem, but I cannot see what I can do to my code to fix this.  Interestingly, when I select from the the taskbar icon to open the small windows form, to see a full description of the status, upon clicking "OK" which minimises and hides the form, the memory useage then drops back down to 1.6MB.  Obviously .NET is finally doing it's own clean-up processes, but this is the only time this will happen.

The reason for the 500 points is more for urgency. ;)

Many thanks,

Kevin Smith

LVL 1
treadmillAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
vb_jonasCommented:
GC.Collect() ?
0

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 
AlexFMCommented:
Your application doesn't use unmanaged code, memory leaks in pure .NET code are impossible (unless there is some bug in .NET Framework). .NET Grabage Collector allows to application to consume almost all available memory before it decides to make collection. I think your code is OK.
0
 
treadmillAuthor Commented:
vb_jonas, using GC.Collect(), after the timer event has elapsed, appears to limit the amount of RAM consumed.  It sits, so far, at about 7.2MB useage. I will keep an eye on this for a little while longer, as it normally takes about 10 minutes or so before it consumes 25MB.

AlexFM, thanks for this information about the GC and .NET's use of memory. Both of your comments have helped solved this problem, as you have made me aware of what .NET will do with memory and how to clear it up, rather than wait for .NET to do it for me.

Now, how do I equally award points to both of you?  Do I accept both of your answers?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.