Can anybody explain why this tiny app's memory usage keeps increasing ?
static class Program
{
private static System.Timers.Timer _TestTimer;
[STAThread]
static void Main()
{
_TestTimer = new System.Timers.Timer();
_TestTimer.Interval = 30;
_TestTimer.Elapsed += new System.Timers.ElapsedEventHandler(_TestTimer_Elapsed);
_TestTimer.Enabled = true;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
static void _TestTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
string test = "tick";
Trace.WriteLine(test);
test = null;
}
}
Thanks! Pika81
You are assuming that the memory usage should not increase. Wrong assumption, that's just not how either the .NET garbage collector or the Windows heap manager work. Both of them work efficiently by using memory that's available for use instead of constantly releasing and reallocating memory.
Let it run for a week. Might go quicker if you make the Interval smaller. Also minimize the form for spectacular effects.
My suggestion would be to crank up Windbg and find out what objects exist in memory.
Agreed that we devs generally use it as the last option but in this case, it would give you the exact reason for the memory increase
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With