473,414 Members | 1,980 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

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.EventArgs e)
{
int nSize = Convert.ToInt32( this.txtBufferSize.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.EventArgs e)
{
m_ar = null;
System.GC.Collect();
this.Text = "Released memory";
}

//Force a garbage collection
private void btnCollectGarbage_Click(object sender, System.EventArgs
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 1844
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**********@talk21.comwrote in message
news:11*********************@q75g2000hsh.googlegro ups.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.EventArgs e)
{
int nSize = Convert.ToInt32( this.txtBufferSize.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.EventArgs e)
{
m_ar = null;
System.GC.Collect();
this.Text = "Released memory";
}

//Force a garbage collection
private void btnCollectGarbage_Click(object sender, System.EventArgs
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%20Mystery.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
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...
11
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...
3
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...
46
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. ...
7
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...
7
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...
6
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...
8
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...
1
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
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...
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
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...

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.