473,769 Members | 7,646 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Memory consumption .NET 1.1 Where is the memory before a garbage collection?

I am trying to identify whether a .NET 1.1 application that I have
written has a memory leak. I thought I understood how .NET memory
management worked, but it appears that there is more to it than I
realised.

I have created a simple app that creates a byte array which is stored
as a member of the application's main form.

The important code is shown below.

private byte[] m_ar; //byte array to store data

private void btnCreateArray_ Click(object sender, System.EventArg s e)
{
int nSize = Convert.ToInt32 ( this.txtBufferS ize.Text);
byte[] buffer = new byte[nSize];
m_ar = buffer;
this.Text = "Grabbed memory";
}

//set the member array to null to allow it to be garbage collected, //
then force a garbage collection.
private void btnReleaseArray _Click(object sender, System.EventArg s e)
{
m_ar = null;
System.GC.Colle ct();
this.Text = "Released memory";
}

//Force a garbage collection
private void btnCollectGarba ge_Click(object sender, System.EventArg s
e)
{
GC.Collect();
}

The user enters a value into the text box txtBufferSize (A typical
test value is 50,000,000).

In Task Manager the amount of virtual memory used increases by about
50MB, which is exactly as you might expect.

However the amount of "Committed Bytes" as shown by the Performance
Monitor remains at a few 100K.

If I then force a garbage collection, then at that point, the number
of committed bytes increases to around 50MB. Task manager continues to
indicate that virtual memory is around 50MB.

My questions are:

Why does it take a garbage collection for the application to "commit"
the bytes?

Where is the memory that is being used before it appears as committed
bytes?

Jun 20 '07 #1
2 1875
First thing to understand is you do not control GC, even if you code it in.
There are other factors that may delay GC even when you call it explicitly.

The memory footprint is part for your app and part for the underlying CLR
and libs you are running. People who come from the COM world often bitch
about this footprint without taking into account the COM libs loaded when
you boot up. That memory appears to be OS memory, so few people account for
it.

If you want a better peek into the GC download process explorer from
Sysinternals (now owned by MS). You can drill down into the process and see
the actual heaps. While this is not a perfect way to find memory leaks, a
huge amount of memory on Gen2 is an indication there might be a problem.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
Co-author: Microsoft Expression Web Bible (upcoming)

*************** *************** *************** ***
Think outside the box!
*************** *************** *************** ***
<ro**********@t alk21.comwrote in message
news:11******** *************@q 75g2000hsh.goog legroups.com...
>I am trying to identify whether a .NET 1.1 application that I have
written has a memory leak. I thought I understood how .NET memory
management worked, but it appears that there is more to it than I
realised.

I have created a simple app that creates a byte array which is stored
as a member of the application's main form.

The important code is shown below.

private byte[] m_ar; //byte array to store data

private void btnCreateArray_ Click(object sender, System.EventArg s e)
{
int nSize = Convert.ToInt32 ( this.txtBufferS ize.Text);
byte[] buffer = new byte[nSize];
m_ar = buffer;
this.Text = "Grabbed memory";
}

//set the member array to null to allow it to be garbage collected, //
then force a garbage collection.
private void btnReleaseArray _Click(object sender, System.EventArg s e)
{
m_ar = null;
System.GC.Colle ct();
this.Text = "Released memory";
}

//Force a garbage collection
private void btnCollectGarba ge_Click(object sender, System.EventArg s
e)
{
GC.Collect();
}

The user enters a value into the text box txtBufferSize (A typical
test value is 50,000,000).

In Task Manager the amount of virtual memory used increases by about
50MB, which is exactly as you might expect.

However the amount of "Committed Bytes" as shown by the Performance
Monitor remains at a few 100K.

If I then force a garbage collection, then at that point, the number
of committed bytes increases to around 50MB. Task manager continues to
indicate that virtual memory is around 50MB.

My questions are:

Why does it take a garbage collection for the application to "commit"
the bytes?

Where is the memory that is being used before it appears as committed
bytes?

Jun 20 '07 #2
Thanks for the message,

I appreciate at least some of the details of garbage collection, and I
do not normally write code that forces GC to occur.

What surprises me is that the 50MB allocated for the large byte array
only appears in the Performance Monitor as CLR Memory (actually as
memory in the large object heap) only AFTER I force a garbage
collection, although it is "shown" as allocated memory within Task
Manager. Is this a "quirk" of either the performance monitor or task
manager, or is the memory really being allocated somewhere else, and
gets "moved" to the Large Object Heap only when the garbage collection
occurs?

The main reason that I wish to know is that I am aware that the memory
usage shown by Task Manager is not very meaningful if memory is not in
short supply (http://getdotnetco.web119.discountas...dncStore/free/
Articles/The%20Memory%20 Mystery.htm), and I am trying to find a more
meaningful measurement of the real memory usage.

Regards

Roger

Jun 21 '07 #3

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

Similar topics

31
9827
by: lawrence | last post by:
I'm not sure how this is normally done, on a large site, perhaps one running Phorum. Occassionally a thread will have hundreds of entries, perhaps a meg or two worth of data. You won't necessarily print all that to the screen, but PHP has to hold it in memory. Run some operations on it, or, more likely, have an array that you keep adding things to, and very soon you run into the 8 meg limit that is the default limit for PHP scripts. ...
11
5812
by: Anze | last post by:
Hi! I have a script that uses a lot of memory and an ISP that has memory-limit set to 10 Mb. The script of course doesn't finish running. :( The program is rather simple - it parses XML into an array and then starts the loop that inserts data into the database. If I use a very large XML file then the PHP crashes inside the loop (Fatal error: Allowed memory size of 10485760 bytes exhausted) - indicating that the problem lies within loop...
3
4149
by: Ian Taite | last post by:
Hello, I'm exploring why one of my C# .NET apps has "high" memory usage, and whether I can reduce the memory usage. I have an app that wakes up and processes text files into a database periodically. What happens, is that the app reads the contents of a text file line by line into an ArrayList. Each element of the ArrayList is a string representing a record from the file. The ArrayList is then processed, and the arraylist goes out of...
46
4160
by: sbayeta | last post by:
Hi, I'd like to know who is responsible of memory recycling and defragmentation in a C/C++ program, assuming all the memory allocation/deallocation is done using malloc/free or new/delete. Thanks
7
1630
by: Casey Leamon | last post by:
I've been noticing that all of my .NET apps seem to progressivly use more and more memory. Even after several reworks of the code I can only manage to slow the growth. Is there some Garbage Collection caveat that's holding old data into higher generations accidentlly? Has anyone else noticed this?
7
2633
by: Claire | last post by:
Im sat here watching task manager and the memory consumption of my application rising second by second. What tools are there out there for me to use to find where it's all going please? (I wish we were able to do garbage collection ourselves. Excruciatingly poor idea microsoft. That's been the most annoying part of dotnet) Ive looked at some web pages talking about using the gc class to force garbage collection. Is this something that can...
6
1927
by: Andy | last post by:
Along with many others I've noticed the large amount of memory that can be taken up by the aspnet_wp.exe. I've found that I can better control and limit this memory consumption by including a GC.Collect() in the Application_EndRequest() event handler in the Global.asax file. Whilst this appears to help my memory consumption issues I've also read that forced GC.Collect() can be inefficient. Assuming that I don't see any adverse effects...
8
8553
by: Adrian | last post by:
Hi I have a JS program that runs localy (under IE6 only) on a PC but it has a memory leak (probably the known MS one!) What applications are there that I could use to look at the memory usage of each object within my JS app to help locate my problem? Thanks
1
2330
by: buu | last post by:
It's strange to me, but, create a dictionary and fill it with 1 mil. of some objects. then, see the memory consumption (arised, of course). then, clean the dictionary.... memory consumption is the same... write MyDic=nothing memory consumption is still the same force GC to collect... memory consumption is little bit smaller
0
10048
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
9996
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,...
0
9865
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
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
6674
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
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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.