Re: Memory leak when using System.Windows.Forms.Timer?

Tech-Archive recommends: Fix windows errors by optimizing your registry



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




.



Relevant Pages

  • Re: animiertes Fenster
    ... mit einem Timer und zusätzlicher Opacity genommen: ... private void Form2_Load(object sender, EventArgs e) ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Re: Wie Timer starten
    ... Jetzt will ich in durch das Klicken eines Buttons (der ein Ereignis ... Wie kann ich nun in der Methode button1_Click den Timer starten?? ... private void button1_Click(object sender, EventArgs e) ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Wie Timer starten
    ... Jetzt will ich in durch das Klicken eines Buttons (der ein Ereignis ... Wie kann ich nun in der Methode button1_Click den Timer starten?? ... private void button1_Click(object sender, EventArgs e) ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Re: Toolbar button retains focus while Click handler executes
    ... event handler. ... void button1_Click(object sender, EventArgs e) ... Timer t = new Timer; ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: Timer thread stops running
    ... In any normal language timer will disappear as soon as you left the Start. ... > protected void Application_Start(Object sender, EventArgs e) ...
    (microsoft.public.dotnet.framework.aspnet)