[Mono-devel-list] Leak in System.Timers.Timer?
Brian Kroeker
bkroeker at nortel.com
Fri Mar 11 13:30:24 EST 2005
The test code I posted creates way more timers than I would in my actual
code - so that the symptoms can be seem more readily. Perhaps this is not a
valid test if the code produces objects faster than the gc collects them. I
did run the same code creating 10 new Object()'s and changed the sleep to
Sleep(0) and didn't see the memory rise. I don't know a lot of the internal
workings of mono, so perhaps this isn't a fair test to see if my issue is
related to the gc or not.
Also, I see the same problem running my app with many fewer timers being
created only it takes several days to see the memory usage rise. Since the
memory usage gradually climbs its not the easiest test case to use to
reproduce the issue (you have to wait a long time), this is why I posted the
modified code.
I did work around my problem by only creating a single timer and reusing it
for the lifetime of my app so its no longer an issue for me.
-----Original Message-----
From: Rafael Teixeira [mailto:monoman at gmail.com]
Sent: Friday, March 11, 2005 11:10 AM
To: Kroeker, Brian [WIC:9D10:EXCH]
Cc: mono-devel-list at lists.ximian.com
Subject: Re: [Mono-devel-list] Leak in System.Timers.Timer?
Our current gc, is conservative and not very aggressive at freeing
resources, you may be creating your objects way too fast...
Can't you reuse the timer? Seems to be a wiser solution reuing objects
as even a good gc may spend precious processing time if it has to
collect zillions of short-lived objects...
Just my 2 cents, :)
On Thu, 10 Mar 2005 15:07:55 -0500, Brian Kroeker <bkroeker at nortel.com>
wrote:
>
>
> I haven't installed mono on windows but using the MS Framework I don't see
> this behavior on windows. Also I don't believe this could be a
> lapsed-listener, since I'm subscribing to an event in the instance of
timer
> - when all references to timer are gone shouldn't the garbage collector
get
> rid of the object including its event and list of delegates? I didn't
think
> the delegates stuck around after the event went away.
>
> Brian
>
>
> -----Original Message-----
> From: mono-devel-list-admin at lists.ximian.com
> [mailto:mono-devel-list-admin at lists.ximian.com]
> Sent: Thursday, March 10, 2005 12:03 PM
> To: mono-devel-list at lists.ximian.com
> Subject: Re: [Mono-devel-list] Leak in System.Timers.Timer?
>
>
> Oh, wait I see you are passing the same one by ref and setting it to null.
> Do you get different behaviour under windows?
>
> Joe Audette <joe_audette at yahoo.com> wrote:
>
> Looks to me like your creating timers in an infinite loop wich would of
> course continue to consume resources
>
> while(true)
> {
> InitTimeout(ref timeout);
> System.Threading.Thread.Sleep(10);
> }
>
> true will always be true so you are spinning off a lot of timers right? Or
> am I missing something?
>
> Regards,
>
> Joe
>
>
> Brian Kroeker <bkroeker at nortel.com> wrote:
>
>
>
> 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
>
> joe_audette at yahoo.com
> http://www.joeaudette.com
> http://www.mojoportal.com
>
>
> joe_audette at yahoo.com
> http://www.joeaudette.com
> http://www.mojoportal.com
--
Rafael "Monoman" Teixeira
---------------------------------------
I'm trying to become a "Rosh Gadol" before my own eyes.
See http://www.joelonsoftware.com/items/2004/12/06.html for enlightment.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20050311/676e3199/attachment.html
More information about the Mono-devel-list
mailing list