473,544 Members | 2,242 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Large Memory Footprint for Simple .NET Apps

Tom
We have a VERY simple .NET C# Form Application, that has about a 23MB
Memory Footprint. It starts a window runs a process and does a regular
expression. I have done a GC.Collect to make sure that, no memory is
lying around. GC reports only 84k of allocations. Starting 5-10 of
this apps is going to start taking a considerable amount of memory. Is
there a way to reduce this?

Tom
Jul 21 '05 #1
6 3248
And what exactly is the 23MB footprint? What Memory counters are you looking
at?

Willy.
"Tom" <ju********@hot mail.com> wrote in message
news:63******** *************** ***@posting.goo gle.com...
We have a VERY simple .NET C# Form Application, that has about a 23MB
Memory Footprint. It starts a window runs a process and does a regular
expression. I have done a GC.Collect to make sure that, no memory is
lying around. GC reports only 84k of allocations. Starting 5-10 of
this apps is going to start taking a considerable amount of memory. Is
there a way to reduce this?

Tom

Jul 21 '05 #2
Tom
Thats my question! What is it?! How would I find out. I am looking at
the Task Manager. The GC only reports about 84k of allocations. The
Win32 Equlivalant of this program would be less than a Meg. My theory
is it is all the memory of having the Assemblies loaded in memory.

"Willy Denoyette [MVP]" <wi************ *@pandora.be> wrote in message news:<#U******* ******@TK2MSFTN GP12.phx.gbl>.. .
And what exactly is the 23MB footprint? What Memory counters are you looking
at?

Willy.
"Tom" <ju********@hot mail.com> wrote in message
news:63******** *************** ***@posting.goo gle.com...
We have a VERY simple .NET C# Form Application, that has about a 23MB
Memory Footprint. It starts a window runs a process and does a regular
expression. I have done a GC.Collect to make sure that, no memory is
lying around. GC reports only 84k of allocations. Starting 5-10 of
this apps is going to start taking a considerable amount of memory. Is
there a way to reduce this?

Tom

Jul 21 '05 #3
Memory counters have a name,f.i.Taskma nager shows 'Mem Usage' and 'VM Size'
per default. The Performance monitor has a whole bunch of named Memory
counters. So when talking about memory consumption you should add the name
of counter you are looking at. Note that "perfmon" also has a number of CLR
specific memory counters that are more important than the Taskman counters.
For the remaining of this discussion I assume you are looking at (but I
could be wrong) Taskmanager's "VM size" , which is the 'wrong' counter to
look at when talking about RAM usage.
'VM size' shows the number of "private bytes" committed to the process, that
doesn't mean all those bytes are taking up physical memory only a part of it
is actually stored in RAM. The number of bytes currently taking up RAM is
shown in the 'Mem Usage' column, this counter is the sum of the private
bytes and shared/shareable bytes currently in RAM.
Shared/Shareable bytes are those that are effectively shared or can possibly
be shared amongst other processes, a small managed program can share some
20-30% of it's 'Mem Usage' or "Working Set" with other non 'managed'
processes and up to 40-70% with other managed processes, depending on the
type of application.
What does this all mean? Suppose you have a managed process (a small
Winforms application) taking 14MB of RAM (Mem Usage),
when starting a second instance, because of code sharing, this will only
take ~30% -70% more RAM. So you can't simply add the 'Mem Usage' counters
like you did in your original posting to calculate the amount of RAM used
when running several instances.

Now why are 'VM Size' and 'Mem Usage' values higher when compared to a
native Win32 process,?
First the CLR is loaded in a managed application, this takes up some MB of
shared/shareable pages - part of it shared with non managed applications and
almost all of it shared with other managed processes.
A winforms application loads (besides other FCL assemblies like System.dll,
Mscorlib.dll etc..) a large part of the Windows.Forms.d ll assembly for the
UI main window initialization, this accounts for a few MB of shareable code
pages not loaded in an unmanaged application.
And for the 'VM Size' here a large part is 'reserved' by the GC heap, note
that only a part of it is actually taking up real memory, as the CLR
pre-allocates a portion which is not completely returned when not in use.
The same effect can be observed with unmanaged applications reserving a lot
of virtual memory as part of pre-allocation of buffers. When the GC heap
runs out op space the CLR will ask the OS for more memory and the VM Size
will grow, if this is paired with a growth of 'MemUsage', it can be an
indication of a managed/unmanaged leak, when VM size grows without ever
shrinking, it is almost certain a leak.

What is the lesson learned?
- Use the permon counters (and learn what they represent) when looking at
memory consumption.
- Use the Working Set counter for the actual RAM usage (if that's important
to you).
- Use "Private bytes" counter to watch for memory leaks (together with the
CLR GC counters to make a distinction between managed/unmanaged heap).
- Learn how Memory is managed in a NT based OS.

Willy.

PS. "Mem Usage" is "Working set bytes" and "WM Size" is "Private Bytes" in
Perfmon.

"Tom" <ju********@hot mail.com> wrote in message
news:63******** *************** ***@posting.goo gle.com...
Thats my question! What is it?! How would I find out. I am looking at
the Task Manager. The GC only reports about 84k of allocations. The
Win32 Equlivalant of this program would be less than a Meg. My theory
is it is all the memory of having the Assemblies loaded in memory.

"Willy Denoyette [MVP]" <wi************ *@pandora.be> wrote in message
news:<#U******* ******@TK2MSFTN GP12.phx.gbl>.. .
And what exactly is the 23MB footprint? What Memory counters are you
looking
at?

Willy.
"Tom" <ju********@hot mail.com> wrote in message
news:63******** *************** ***@posting.goo gle.com...
> We have a VERY simple .NET C# Form Application, that has about a 23MB
> Memory Footprint. It starts a window runs a process and does a regular
> expression. I have done a GC.Collect to make sure that, no memory is
> lying around. GC reports only 84k of allocations. Starting 5-10 of
> this apps is going to start taking a considerable amount of memory. Is
> there a way to reduce this?
>
> Tom

Jul 21 '05 #4
Oh I forgot:
What are the lessons learned?
- Yes, a managed application's memory footprint is larger than an unmanaged
, simply because the runtime is part of the process.

Willy.
"Willy Denoyette [MVP]" <wi************ *@pandora.be> wrote in message
news:uP******** ******@TK2MSFTN GP12.phx.gbl...
Memory counters have a name,f.i.Taskma nager shows 'Mem Usage' and 'VM
Size' per default. The Performance monitor has a whole bunch of named
Memory counters. So when talking about memory consumption you should add
the name of counter you are looking at. Note that "perfmon" also has a
number of CLR specific memory counters that are more important than the
Taskman counters.
For the remaining of this discussion I assume you are looking at (but I
could be wrong) Taskmanager's "VM size" , which is the 'wrong' counter to
look at when talking about RAM usage.
'VM size' shows the number of "private bytes" committed to the process,
that doesn't mean all those bytes are taking up physical memory only a
part of it is actually stored in RAM. The number of bytes currently taking
up RAM is shown in the 'Mem Usage' column, this counter is the sum of the
private bytes and shared/shareable bytes currently in RAM.
Shared/Shareable bytes are those that are effectively shared or can
possibly be shared amongst other processes, a small managed program can
share some 20-30% of it's 'Mem Usage' or "Working Set" with other non
'managed' processes and up to 40-70% with other managed processes,
depending on the type of application.
What does this all mean? Suppose you have a managed process (a small
Winforms application) taking 14MB of RAM (Mem Usage),
when starting a second instance, because of code sharing, this will only
take ~30% -70% more RAM. So you can't simply add the 'Mem Usage' counters
like you did in your original posting to calculate the amount of RAM used
when running several instances.

Now why are 'VM Size' and 'Mem Usage' values higher when compared to a
native Win32 process,?
First the CLR is loaded in a managed application, this takes up some MB of
shared/shareable pages - part of it shared with non managed applications
and almost all of it shared with other managed processes.
A winforms application loads (besides other FCL assemblies like
System.dll, Mscorlib.dll etc..) a large part of the Windows.Forms.d ll
assembly for the UI main window initialization, this accounts for a few MB
of shareable code pages not loaded in an unmanaged application.
And for the 'VM Size' here a large part is 'reserved' by the GC heap, note
that only a part of it is actually taking up real memory, as the CLR
pre-allocates a portion which is not completely returned when not in use.
The same effect can be observed with unmanaged applications reserving a
lot of virtual memory as part of pre-allocation of buffers. When the GC
heap runs out op space the CLR will ask the OS for more memory and the VM
Size will grow, if this is paired with a growth of 'MemUsage', it can be
an indication of a managed/unmanaged leak, when VM size grows without ever
shrinking, it is almost certain a leak.

What is the lesson learned?
- Use the permon counters (and learn what they represent) when looking at
memory consumption.
- Use the Working Set counter for the actual RAM usage (if that's
important to you).
- Use "Private bytes" counter to watch for memory leaks (together with the
CLR GC counters to make a distinction between managed/unmanaged heap).
- Learn how Memory is managed in a NT based OS.

Willy.

PS. "Mem Usage" is "Working set bytes" and "WM Size" is "Private Bytes" in
Perfmon.

"Tom" <ju********@hot mail.com> wrote in message
news:63******** *************** ***@posting.goo gle.com...
Thats my question! What is it?! How would I find out. I am looking at
the Task Manager. The GC only reports about 84k of allocations. The
Win32 Equlivalant of this program would be less than a Meg. My theory
is it is all the memory of having the Assemblies loaded in memory.

"Willy Denoyette [MVP]" <wi************ *@pandora.be> wrote in message
news:<#U******* ******@TK2MSFTN GP12.phx.gbl>.. .
And what exactly is the 23MB footprint? What Memory counters are you
looking
at?

Willy.
"Tom" <ju********@hot mail.com> wrote in message
news:63******** *************** ***@posting.goo gle.com...
> We have a VERY simple .NET C# Form Application, that has about a 23MB
> Memory Footprint. It starts a window runs a process and does a regular
> expression. I have done a GC.Collect to make sure that, no memory is
> lying around. GC reports only 84k of allocations. Starting 5-10 of
> this apps is going to start taking a considerable amount of memory. Is
> there a way to reduce this?
>
> Tom


Jul 21 '05 #5
Willy,
What are the lessons learned?
- Yes, a managed application's memory footprint is larger than an

unmanaged > , simply because the runtime is part of the process.

Nothing about the contents of your message, however in my opinion is your
above statement probably always true for small programs, however not for
large programs.

There the memory use can be earned back by reusing a lot of code in a more
efficient way. That is why runtime parts where devolleped for in the first
place in past.

Just my thought

Cor
Jul 21 '05 #6
Cor,

True, the WS shared pages overhead stays more or less the same value (lets
say 5 -8MB) independent of the "size" of the program. The bulk of a large
program (in both WS and Virtual bytes size) is determined by the number and
size of the objects in the GC heap and the size and number of program
assemblies loaded.

Willy.

"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:OA******** *****@TK2MSFTNG P12.phx.gbl...
Willy,
What are the lessons learned?
- Yes, a managed application's memory footprint is larger than an

unmanaged > , simply because the runtime is part of the process.

Nothing about the contents of your message, however in my opinion is your
above statement probably always true for small programs, however not for
large programs.

There the memory use can be earned back by reusing a lot of code in a more
efficient way. That is why runtime parts where devolleped for in the
first
place in past.

Just my thought

Cor

Jul 21 '05 #7

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

Similar topics

2
2941
by: assi | last post by:
Hello all We are developing a large dotnet application, which includes ~ 120 assemblies. (total size of all binaries is ~ 20MB). Our application also references the following dotnet assemblies: System,System.XML, System.Windows.Forms, System.Drawing, System.Data, System.Design. We use dotnet framework 1.1 During initialization, the...
3
2153
by: Derrick | last post by:
I am reading in xml files that equate to sql tables, via XmlDataDocument, and then operating on the DataSet. With the most simple app that just loads the xml doc, I see the memory footprint of the app grow to roughly 5x the size of the xml document after the xml doc is read. Can anyone comment on this? Is this expected? Below are two...
1
3993
by: lwickland | last post by:
Summary: System.Net.ScatterGatherBuffers.MemoryChuck allocates inordinately large bytes when sending large post data. The following application consumes inordinate quantities of memory. My code does not explicitly allocate memory in a loop nor does it explicitly allocate large blocks of memory. Yet, the application’s memory footprint...
8
1856
by: Bob Dufour | last post by:
We got a windows form application that we wrote in VB.Net. Essentially its a manager for a list of persons and their contacts and some other info about the persons. No rocket science but lots of textboxes and comboxes to use lookup lists, some tab controls allow viewing of data about a person in logical groupings. We find that as we load...
6
386
by: Tom | last post by:
We have a VERY simple .NET C# Form Application, that has about a 23MB Memory Footprint. It starts a window runs a process and does a regular expression. I have done a GC.Collect to make sure that, no memory is lying around. GC reports only 84k of allocations. Starting 5-10 of this apps is going to start taking a considerable amount of memory....
11
2472
by: Benny | last post by:
I just wanted to throw the discussion out there on what the best practice people feel is for using large objects in a foreach loop. For example if you are reusing an Image object in a loop like this (letters above snippets are for reference purposes): A foreach ( string s in myList ) { Image img = Image.FromFile( s ); // operate on img
3
3193
by: =?Utf-8?B?VG9kZA==?= | last post by:
What is the memory footprint of static methods of a windows app running on a server when the server spins up multiple instances of the application? In my envirionment, we have a Citrix server farm running .Net 2.0 windows apps. Does the framework allow for instances of the same application to access the same memory space where static...
0
1133
by: volt9000 | last post by:
I'm using PdfSharp (an open-source PDF manipulation library) to generate a very large PDF ( 1500+ pages.) My program crashes before reaching the end because of the massive amounts of memory being used (after 750 entries the memory footprint is ONE GIGABYTE.) So I've gotten around this by splitting up the word: every X number of entries, I...
5
3251
by: DBC User | last post by:
How would you develop a zero footprint application, is the smart client application a zero footprint application? Thanks.
0
7439
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7395
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7722
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5935
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5310
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4932
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3425
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1851
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
997
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.