Re: Memory leak when using System.Windows.Forms.Timer?
- From: "Alvin Bruney [MVP]" <some guy without an email address>
- Date: Tue, 10 Jul 2007 21:53:54 -0400
hmmm, i'd run windbg against it to rule out the managed portion first. Have
you? I do recall a thread in here about a few months ago talking about just
that. I don't remember the solution though
--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
https://www.microsoft.com/MSPress/books/10933.aspx
OWC Black Book www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
"Guru" <g.p> wrote in message news:uC8nnOlwHHA.1204@xxxxxxxxxxxxxxxxxxxxxxx
I am seeing a constant increase in Private bytes of a process that
continuosly creates timers and disposes them. This increase is in the
unmanaged memory and not the .NET managed memory(as shown by PerfMon
counters). Has anyone seen this kind of leak before?
The leak is very small, creating and destroying 100 timers every 8 seconds
seems to leak about 26 MB over 6 days.
This is the code of a simple WinForms app that is simply creating timers
and destroying them.(timer1_Tick runs every 4 seconds)
namespace TimerTest
{
public partial class Form1 : Form
{
List<Timer> m_timerList = new List<Timer>();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
if (m_timerList.Count == 0)
{
for (int i = 0; i < 100; i++)
{
Timer timer = new Timer();
timer.Interval = 1000;
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
m_timerList.Add(timer);
}
}
else
{
foreach (Timer timer in m_timerList)
{
timer.Tick -= new EventHandler(timer_Tick);
timer.Stop();
timer.Dispose();
}
m_timerList.Clear();
}
}
void timer_Tick(object sender, EventArgs e)
{
}
}
}
Any help?
Thanks,
Guru
.
- References:
- Prev by Date: Re: Running Excel in a console app
- Next by Date: Re: Application Center Test for ASP.NET 2.0 application
- Previous by thread: Memory leak when using System.Windows.Forms.Timer?
- Next by thread: Re: Memory leak when using System.Windows.Forms.Timer?
- Index(es):
Relevant Pages
|