Groups | Blog | Home
all groups > dotnet performance > february 2005 >

dotnet performance : memory leak when using Timer control and sleep


LZhao
2/17/2005 4:09:01 PM
Hi,

We have find memory leaks when we tried to use timer to raise event at
specified
interval. The OS we use is: Windows XP Professional Version 2002, service
Pack 2,
IDE is: Visual Studio .NET2003. Microsoft .NET Framework 1.1, version
1.1.4322 SP1. To repeat this problem,

1. creat a VB windows solution
2. on the form, add a timer control, set the property interval to 100
3. add a button, name it "start"
4. add an event handler( command_click) to the button "start"
5. in the event handler, start the timer
6. watch in the "task manager", memory is prograssively increase,
7. to make this problem more clear, add another timer, set the interval to
10, again, when the button "start" clicks, start both the timer. this time
you probably will
notice the memory leaking faster, in 10 minutes, you will find it is leaking
around 1MB.


I tried to change the timer control to System.timers.timer, and use call
back functions at the specified interval, I have the same problem. Further
investigation into the memory leaking, we found if you put the thread into
sleep at certain amount of time, the memory leaks as well.

Is ther any one who knows why? This memory leak crashes our application.
I tried to force garbage colletion, things getting even worse.

Any suggestions are welcome.
thanks very much
Lihui




Alvin Bruney [MVP]
2/18/2005 12:15:58 PM
I'm looking into this.

Using C# though. Initially, I do see memory climbing but not significantly.
I'm going to let it run for a couple of hours in release mode before getting
back to you.

--
Regards,
Alvin Bruney [Microsoft MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ http://www.lulu.com/owc
----------------------------------------------------------


[quoted text, click to view]

Alvin Bruney [MVP]
2/18/2005 3:40:53 PM
You must be running your production application in debug mode :-(. The
release version uses about 200k of memory and never climbs higher. I have
the same system as u, except that I used C# in release mode. The debug
version continued to climb quite possibly, it may have made it to 1meg like
u said.

--
Regards,
Alvin Bruney [Microsoft MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ http://www.lulu.com/owc
----------------------------------------------------------


[quoted text, click to view]

AddThis Social Bookmark Button