Runtime and OS report different mem usage

G

Guest

Hi
I am working on a pure managed windows application that creates large byte arrays at run time. In fact it creates a 50M byte array when the application starts

public static byte[] buffer = new byte[1024*1024*50]

I am using System.GC.GetTotalMemory() to monitor the memory usage. It is consistent with what I can imagine. The memory usage is a little bit above 50M. During runtime this application reads large files (between 25 to 46MB) but it does not reallocate buffer. Each time only one file can be processed and the above 50MB buffer is used

However, if I use Windows Task Manager/Processes and check the memory usage of this application, I see the memory usage is between 75 to 130 MB. This result in some serious diskswapping activities on a PC with 256MB memory

Do you know why there is a discrepency of mem usage between the runtime reports and what the OS reports

I am using .NET SDK1.1 on XP Pro and Win Server 2003

Thank you for your help
 
W

Willy Denoyette [MVP]

Geng Sheng said:
Hi,
I am working on a pure managed windows application that creates large byte
arrays at run time. In fact it creates a 50M byte array when the
application starts.

public static byte[] buffer = new byte[1024*1024*50];

I am using System.GC.GetTotalMemory() to monitor the memory usage. It is
consistent with what I can imagine. The memory usage is a little bit above
50M. During runtime this application reads large files (between 25 to
46MB) but it does not reallocate buffer. Each time only one file can be
processed and the above 50MB buffer is used.

However, if I use Windows Task Manager/Processes and check the memory
usage of this application, I see the memory usage is between 75 to 130 MB.
This result in some serious diskswapping activities on a PC with 256MB
memory.

Do you know why there is a discrepency of mem usage between the runtime
reports and what the OS reports?

I am using .NET SDK1.1 on XP Pro and Win Server 2003.


Thank you for your help.


What counters are you looking at in the Taskmanager?
The Taskmanager has no counter for the GC.GetTotalMemory value, so you are
actually comparing two different things.
If you need a consistent view of the memory consumption, start the
performance managed and look at the CLR Memory counters category.

Willy.
 
G

Guest

I am using Windows Task Manager\Processes by press control-alt-delete then choose "task list". It is a table with the following columns
Image Name, PID, CPU, CPU Time, Mem Usage

I then found the application process name and check the Mem Usage here. By the way, I tried to use PerfMon but I do not know how to enter a specific "Image Name" in those memory counters

On the other hand I am using System.Console to write out System.GC.GetTotalMemory(). That number is very different from what Task Manager reports. This is where the problem is, I do not know what caused the OS to allocate that much memory since I am not reallocating any big objects.
 
W

Willy Denoyette [MVP]

"Mem Usage" is the same counter as the "Working Set" size, that is the size
in bytes of the process pages actually mapped to RAM.
System.GC.GetTotalMemory() only returns the size of the GC heap, which is
only a part of the WS.

Without seeing a piece of code it's hard to tell what accounts for this high
WS usage.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top