473,466 Members | 1,333 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Reducing memory usage in a windows service

I've written a basic windows service to provide some helper xml functions for
my web methods and even thou the service is only about 1k lines long with 1
timer, its mem usage is 10m and its vm mem usage is 14! The same code written
as a program that requires you to click on the menu options to fire off the
events takes up 4/9mb.

I've seen examples where calling SetProcessWorkingSetSize(hWnd, -1, -1); does
the same thing as minimizing a program to reduce the memory use but I can't
minimize a service and calling the setprocess function lowers the memory usage
by 0 bytes.

Are there any other ways to lower the memory usage? Even after some 40+ hours
of running the service was still consuming 10mb of ram. I just dont see how 1
timer and some xml calls with file operations takes up 10mb.
Nov 16 '05 #1
8 15914
Has it been compiled as a Release versus the default Debug?

Patrick Altman
"Greg Merideth" <gm**************@this.forwardtechnology.net> wrote in
message news:Ed********************@comcast.com...
I've written a basic windows service to provide some helper xml functions for my web methods and even thou the service is only about 1k lines long with 1 timer, its mem usage is 10m and its vm mem usage is 14! The same code written as a program that requires you to click on the menu options to fire off the events takes up 4/9mb.

I've seen examples where calling SetProcessWorkingSetSize(hWnd, -1, -1); does the same thing as minimizing a program to reduce the memory use but I can't minimize a service and calling the setprocess function lowers the memory usage by 0 bytes.

Are there any other ways to lower the memory usage? Even after some 40+ hours of running the service was still consuming 10mb of ram. I just dont see how 1 timer and some xml calls with file operations takes up 10mb.

Nov 16 '05 #2
Greg,

You should expect this. The 10 MB is for the runtime, mainly for the
memory management. This is just the price you pay for it.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Greg Merideth" <gm**************@this.forwardtechnology.net> wrote in
message news:Ed********************@comcast.com...
I've written a basic windows service to provide some helper xml functions
for my web methods and even thou the service is only about 1k lines long
with 1 timer, its mem usage is 10m and its vm mem usage is 14! The same
code written as a program that requires you to click on the menu options
to fire off the events takes up 4/9mb.

I've seen examples where calling SetProcessWorkingSetSize(hWnd, -1, -1);
does the same thing as minimizing a program to reduce the memory use but I
can't minimize a service and calling the setprocess function lowers the
memory usage by 0 bytes.

Are there any other ways to lower the memory usage? Even after some 40+
hours of running the service was still consuming 10mb of ram. I just dont
see how 1 timer and some xml calls with file operations takes up 10mb.

Nov 16 '05 #3
Greg Merideth wrote:
I've written a basic windows service to provide some helper xml
functions for my web methods and even thou the service is only about
1k lines long with 1 timer, its mem usage is 10m and its vm mem usage
is 14! The same code written as a program that requires you to click
on the menu options to fire off the events takes up 4/9mb.
See: Analyzing Common CLR Performance Problems
http://blogs.msdn.com/akhune/archive...11/153734.aspx

In short: The GC always allocated at al lot of memory in advance...
I've seen examples where calling SetProcessWorkingSetSize(hWnd, -1,
-1); does the same thing as minimizing a program to reduce the memory
use but I can't minimize a service and calling the setprocess function
lowers the memory usage by 0 bytes.
With 'SetProcessWorkingSetSize' you do not minimize the memory!!! you only
minimize the working set (and thus leads to more page-faults).

Are there any other ways to lower the memory usage? Even after some
40+ hours of running the service was still consuming 10mb of ram. I
just dont see how 1 timer and some xml calls with file operations
takes up 10mb.


To reduce the memory usage dramatically write your code in unmanaged C++.

I think with using the server-GC you can also reduce some preallocated
memory (but I forgott the link...)

Greetings
Jochen
Nov 16 '05 #4
Hello Patrick,
Has it been compiled as a Release versus the default Debug?


Would this make a difference !?
The Debug version only has the "DebuggableAttribute" set to (true, true).

This only disables the optimizer and does not track some JIT infos...

Greetings
Jochen
Nov 16 '05 #5
Hi,

In my experience I think that around 8-10 is the lower memory consuption of
any .net program, Do you really find that big?
Doom 3 consume around 500 MB :)

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Greg Merideth" <gm**************@this.forwardtechnology.net> wrote in
message news:Ed********************@comcast.com...
I've written a basic windows service to provide some helper xml functions for my web methods and even thou the service is only about 1k lines long with 1 timer, its mem usage is 10m and its vm mem usage is 14! The same code written as a program that requires you to click on the menu options to fire off the events takes up 4/9mb.

I've seen examples where calling SetProcessWorkingSetSize(hWnd, -1, -1); does the same thing as minimizing a program to reduce the memory use but I can't minimize a service and calling the setprocess function lowers the memory usage by 0 bytes.

Are there any other ways to lower the memory usage? Even after some 40+ hours of running the service was still consuming 10mb of ram. I just dont see how 1 timer and some xml calls with file operations takes up 10mb.

Nov 16 '05 #6
Its in release mode but after reading the other messages I'll look into moving
the entire set of helper functions into c++ to lower the memory consumption.

I understand that the memory management is part of it so mabye the .net c# way
isn't a good way to go, even with the ease of it, as a process to create
services. Mabye with visual studio 2010 it might be less memory intensive :)

Now to go mess up my machine with c++!

Patrick Altman wrote:
Has it been compiled as a Release versus the default Debug?

Patrick Altman
"Greg Merideth" <gm**************@this.forwardtechnology.net> wrote in
message news:Ed********************@comcast.com...
I've written a basic windows service to provide some helper xml functions


for
my web methods and even thou the service is only about 1k lines long with


1
timer, its mem usage is 10m and its vm mem usage is 14! The same code


written
as a program that requires you to click on the menu options to fire off


the
events takes up 4/9mb.

I've seen examples where calling SetProcessWorkingSetSize(hWnd, -1, -1);


does
the same thing as minimizing a program to reduce the memory use but I


can't
minimize a service and calling the setprocess function lowers the memory


usage
by 0 bytes.

Are there any other ways to lower the memory usage? Even after some 40+


hours
of running the service was still consuming 10mb of ram. I just dont see


how 1
timer and some xml calls with file operations takes up 10mb.


Nov 16 '05 #7
Reducing the working set by calling SetProcessWorkingSetSize, only works for
UI style applications and is considered bad practice.
Not sure what you mean with "set of helper functions into c++ ", but if you
mean by that that you are reimplementing part of your service in C++ and
keep another part managed, then this won't reduce the working set.
Also I'm not clear on what memory counter you are looking at? If it's the
"working set" you should know that a large amount of this one consists of
shared/shareable pages.
Willy.
"Greg Merideth" <gm**************@this.forwardtechnology.net> wrote in
message news:Jd********************@comcast.com...
Its in release mode but after reading the other messages I'll look into
moving the entire set of helper functions into c++ to lower the memory
consumption.

I understand that the memory management is part of it so mabye the .net c#
way isn't a good way to go, even with the ease of it, as a process to
create services. Mabye with visual studio 2010 it might be less memory
intensive :)

Now to go mess up my machine with c++!

Patrick Altman wrote:
Has it been compiled as a Release versus the default Debug?

Patrick Altman
"Greg Merideth" <gm**************@this.forwardtechnology.net> wrote in
message news:Ed********************@comcast.com...
I've written a basic windows service to provide some helper xml functions


for
my web methods and even thou the service is only about 1k lines long with


1
timer, its mem usage is 10m and its vm mem usage is 14! The same code


written
as a program that requires you to click on the menu options to fire off


the
events takes up 4/9mb.

I've seen examples where calling SetProcessWorkingSetSize(hWnd, -1, -1);


does
the same thing as minimizing a program to reduce the memory use but I


can't
minimize a service and calling the setprocess function lowers the memory


usage
by 0 bytes.

Are there any other ways to lower the memory usage? Even after some 40+


hours
of running the service was still consuming 10mb of ram. I just dont see


how 1
timer and some xml calls with file operations takes up 10mb.



Nov 16 '05 #8
..NET programs don't use all the memory they allocate. If you fill up your
ram, the memory management of .NET applications will change to a more a more
agressive mode. For exemple I have a "small" winform application that takes
20Mb at launch. If I fill up my ram (by launching 3 virtual machines, damn
1Gb is hard to fill up!) it's memory usage goes down to 2Mb.

Of course, going C++ is going to save you even more than that.

Etienne Boucher
Nov 16 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ianstirkcv | last post by:
Hello, I wonder if you can please help… We are running a web application built using .net framework version 1.0, service pack 2, running on Windows 2000 server, service pack 3. The server has...
4
by: Frank Esser | last post by:
I am using SQL 8 Personal edition with sp2 applied. I set the max server memory to 32MB and leave the min server memory at 0. When my application starts hitting the database hard the memory usage...
2
by: Mikael Sorensen | last post by:
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. ...
2
by: Cider123 | last post by:
I'm posting this in anticipation for troubleshooting tomorrow, however: I have a project I just finished up that I'm beta testing now. It's comprised of a main core Window Service, with...
6
by: John Wood | last post by:
As everybody points out, the best way to reduce the memory footprint of a ..net application is to minimize it and restore it. This can make my app go from 40Mb of usage to about 3Mb of usage. Of...
7
by: HeatherS | last post by:
We are having issues with our windows services using memory and never releasing it. We have one service that has a file watcher which takes an xml file, inserts some records into a database, and...
6
by: Jakub Cermak | last post by:
Hi all, how can I reduce reserved memory for my process? Because according to ProcessExporer (and GC.GetTotalMemory() and taskmanager) I use about 5-6MB and reserved memory is nearly 70MB. I don't...
9
by: Adam Right | last post by:
Hi, Anyone suffers from the high memory usage of C# in windows applications? Is there a solution for that problem? Thanks...
1
by: booksnore | last post by:
I've been having a discussion with a collegue concerning how to identify memory leaks with applications running within the CLR. I read the microsoft article http://support.microsoft.com/kb/318263...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.