Windows service memory management

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've written a windows service (VB.NET 2003). When running, it consumes between 20-40 MB memory.

How do I optimize the memory usage?

I've set all objects to Nothing when I'm done using them.

What else can i do?

Regards,
Mikael
 
Mikael,

Unless your memory usage keeps growing uncontrollably (i.e. after a few days
of having your service running it gets larger and larger), I wouldn't worry
about it.

..NET has a pretty complex memory management engine. On systems with a lot of
free memory, it may allocate more than it needs to keep performace up. Also,
when a .NET application is loaded, a lot of memory has to be allocated for
hosting the CLR. Even though task manager says it's using 40mb, not all of
this may be allocated, and some may still be available to other applicatons
to use if the system runs low on memory. Don't judge your total memory usage
on this figure.

Unless you're a pretty advanced user and want to get your hands dirty with
the operating system memory management features, don't worry about it.
I've set all objects to Nothing when I'm done using them.

Setting references to nothing does not de-allocate the memory used by
objects. They stay in the background until the Garbage collector comes along
and finalizes them. If you are using objects that implement the IDisposable
interface or have a "dispose" or "close" method on them, make sure you call
that before setting the object to nothing - this will ensure any unmanaged
resources (such as database connections or files) will be closed properly.

HTH,

Trev.
 
Thanks Tre

I will monitor the service for about a week and see what happends

Regards
Mikael
 
Back
Top