473,748 Members | 7,142 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 3276
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
2961
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 application scans a directory and loads the assemblies (using Assembly.LoadFrom). It then scans all...
3
2166
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 samples, the first hits northwind, and creates a 19meg (roughly, on my machine) xml file. The second...
1
4010
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 will grow as large as 370 MB. Rarely will it run to completion; usually, it throws an out of memory...
8
1872
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 the app with only a few hundred records of data in a lookup list (Rough estimate of data only at...
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. Is there a way to reduce this? Tom
11
2503
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
3210
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 methods are stored (assuming the security context is the same for each instance)?
0
1150
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 close the PDF and start a new one, with the intention of combining the PDFs at the end. The problem...
5
3259
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
8830
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9541
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9370
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9321
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 most users, this new feature is actually very convenient. If you want to control the update process,...
1
6796
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6074
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4602
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3312
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
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.