Home All Groups Group Topic Archive Search About

Memoryleak in .net service

Author
11 Oct 2006 10:38 AM
Johan Karlsson
Hi!
We have a singlecall server application that runs inside a .net service. The
service uses two System.Threading.Timer's to call to methods every 10
seconds. Something like this:

Dim ad as new AlarmsData
ad.handleAlarm( )
ad = nothing

The application doesn't seem to release objects created. After 24 hours the
total amount of memory allocated is about 400 MB.

Looking at the performance counters for .net memory

Total allocated Bytes 386 000 000
Heapsize gen 2 - 381 400 000

I think this tells me that I have a large number of long living objects
still references by the GC. Manual GC.Collect doesn't do anything.

The HandleAlarms call only does a couple of database calls (using enterprise
library) and since the AlarmsData object itself goes out of scope at the end
of the timer method, I'd figured that it would be destroyed?

Any pointers?

Thanks
Johan

Author
11 Oct 2006 6:44 PM
Mattias Sjögren
Johan,

>The HandleAlarms call only does a couple of database calls (using enterprise
>library) and since the AlarmsData object itself goes out of scope at the end
>of the timer method, I'd figured that it would be destroyed?
>
>Any pointers?

As long as the Timer object is alive and not disposed, it will keep
alive whatever object the TimerCallback you created it with refers to
(if it points to an instance method). Could that be the reason your
objects stay in memory?


Mattias

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Author
11 Oct 2006 8:05 PM
Johan Karlsson
We tracked down the leak to an event handler argument class that somehow
survived each call. Removing the event fixed the problem. Thanks for you
input though. Typical design error.

/Johan

Show quote
"Mattias Sjögren" wrote:

> Johan,
>
> >The HandleAlarms call only does a couple of database calls (using enterprise
> >library) and since the AlarmsData object itself goes out of scope at the end
> >of the timer method, I'd figured that it would be destroyed?
> >
> >Any pointers?
>
> As long as the Timer object is alive and not disposed, it will keep
> alive whatever object the TimerCallback you created it with refers to
> (if it points to an instance method). Could that be the reason your
> objects stay in memory?
>
>
> Mattias
>
> --
> Mattias Sjögren [C# MVP]  mattias @ mvps.org
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.
>

AddThis Social Bookmark Button