Quantcast
Channel: Common Language Runtime Internals and Architecture forum
Viewing all articles
Browse latest Browse all 1710

Memory leak in system timer event in framework 3.5 and in framework 2.0

$
0
0

I use C# in VS 2008 framework 3.5 and VS2005 framework 2.0.

When I use system timer, I find in every several seconds it increases 8K memory usage and keep increasing as long as you wish. Here is the code. You can cut and paste it in console application in either vs2008 or vs2005, compile and run it. Then you can observe the memory increase. Does anyone have a solution or work around?


 

Using System;

using System.Timers;

publicclassTimer1

{

publicstaticvoid Main()

{

System.Timers.Timer aTimer = new System.Timers.Timer();

aTimer.Elapsed += newElapsedEventHandler(OnTimedEvent);

aTimer.Interval =75;

aTimer.Enabled = true;

Console.WriteLine("Press the Enter key to exit the program.");

Console.ReadLine();

GC.KeepAlive(aTimer);

}

privatestaticvoid OnTimedEvent(object source, ElapsedEventArgs e)

{

Console.WriteLine("Hello World!");

}

}


Viewing all articles
Browse latest Browse all 1710

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>