Memory leakage in VB.Net

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello, We have a problem with a small GUI application that leaks memory. The GC seems to miss out on things. A small code snippet that will leak

' This is the method to run when the timer is raised
Private Sub TimerEventProcessor2(ByVal sender As Object, ByVal e As System.EventArgs
Dim stText As Strin
stText = Me.Button1.Tex
stText +=
Me.Button1.Text = stTex
End Su
As you can see everytime the timer event is raised the button text is incremented and hence the application leaks memory. This snippet has been written in shorter forms as well still the same result. Memory leakage. The target is a CE Panel PC from Advantech with an XScale processor
brgd
/maw
 
Have you tried calling GC.Collect() ?

Mawa said:
Hello, We have a problem with a small GUI application that leaks memory.
The GC seems to miss out on things. A small code snippet that will leak.
' This is the method to run when the timer is raised.
Private Sub TimerEventProcessor2(ByVal sender As Object, ByVal e As System.EventArgs)
Dim stText As String
stText = Me.Button1.Text
stText += 1
Me.Button1.Text = stText
End Sub
As you can see everytime the timer event is raised the button text is
incremented and hence the application leaks memory. This snippet has been
written in shorter forms as well still the same result. Memory leakage. The
target is a CE Panel PC from Advantech with an XScale processor.
 
Mawa said:
Hello, We have a problem with a small GUI application that leaks memory.
The GC seems to miss out on things. A small code snippet that will leak.

The GC just never gets to running, is all.
GC will only run on its own when you are getting low on memory, so as long
at lots of memory are available, your app will leak in the described manner.
(OK, I admit that there are a few other cases where GC will run on its own.)

Try to call the GC specifically, thus getting a premature garbage
collection, just as Mike suggests.

/Keld Laursen
 
There's no reason this code would "leak". What kind of Timer is it (Form or
Thread)?

-Chris


Mawa said:
Hello, We have a problem with a small GUI application that leaks memory.
The GC seems to miss out on things. A small code snippet that will leak.
' This is the method to run when the timer is raised.
Private Sub TimerEventProcessor2(ByVal sender As Object, ByVal e As System.EventArgs)
Dim stText As String
stText = Me.Button1.Text
stText += 1
Me.Button1.Text = stText
End Sub
As you can see everytime the timer event is raised the button text is
incremented and hence the application leaks memory. This snippet has been
written in shorter forms as well still the same result. Memory leakage. The
target is a CE Panel PC from Advantech with an XScale processor.
 
The GC does run periodically in addition to when you are running low on
memory. However, since collection is a relatively time-consuming operation
it is not performed unless the GC detects that a substantial amount of
memory (750kb) has been allocated since the previous collection. So perhaps
you are just seeing that "normal" accumulation of garbage that will the
collected at some time in the future.

I would almost never recommend that an application call GC.Collect itself.
As an experiment, it might be useful to try it in this instance to see if
in fact your memory use drops as expected. If that is the case, I think you
are seeing the normal accumulation of garbage and shouldn't be concerned.

--------------------
From: "Keld Laursen [eMVP]" <[email protected]>
Subject: Re: Memory leakage in VB.Net
Date: Tue, 6 Apr 2004 15:55:43 +0200

Mawa said:
Hello, We have a problem with a small GUI application that leaks memory.
The GC seems to miss out on things. A small code snippet that will leak.
The GC just never gets to running, is all.

GC will only run on its own when you are getting low on memory, so as long
at lots of memory are available, your app will leak in the described manner.
(OK, I admit that there are a few other cases where GC will run on its own.)

Try to call the GC specifically, thus getting a premature garbage
collection, just as Mike suggests.

/Keld Laursen


This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top