[Mono-devel-list] Leak in System.Timers.Timer?

Brian Kroeker bkroeker at nortel.com
Thu Mar 10 13:09:40 EST 2005


I'm seeing what looks like a memory leak somewhere in System.Timers.Timer.
I'm using mono 1.1.4 on a linux system. The code I used to reproduce the
problem is:

----------------------
using System;


namespace TimerTest
{
    public class TimerTest
    {
        static void Main(string[] args)
        {
            TimerTest test = new TimerTest();

            test.Run();
        }

        public TimerTest()
        {
        }

        public void Run()
        {
            System.Timers.Timer timeout = null;

            while(true)
            {
                InitTimeout(ref timeout);
                System.Threading.Thread.Sleep(10);
            }
        }

        private void InitTimeout(ref System.Timers.Timer timer)
        {
            if(timer != null)
            {
                timer.Stop();
                timer = null;
            }

            timer = new System.Timers.Timer();
            timer.AutoReset = false;
            timer.Elapsed += new
System.Timers.ElapsedEventHandler(OnTimeout);
            timer.Interval = 30000;
            timer.Start();
        }

        private void OnTimeout(object source, System.Timers.ElapsedEventArgs
e)
        {
        }
    }
}
--------------

Does anyone else see this problem? Am I missing something here? I see the
memory usage on my system increase fairly quickly.

Thanks,
Brian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20050310/81978766/attachment.html 


More information about the Mono-devel-list mailing list