views:

484

answers:

2

My program has 7,667,712 bytes of committed heap, yet it has 33,546,240 reserved heap bytes! I can see that the program is using around 44 MB of private bytes. How can I get the .NET GC to reserve less space for the managed heap?

+3  A: 

Just because your process has reserved memory, doesn't mean it's using that memory.

In Windows, Reserved Memory means that your process has mapped pages into it's address space. Physical memory is allocated by committing those reserved pages. Of course, even then you are not necessarily using that memory, because committed pages can be swapped out to the page file, temporarily releasing the underlying physical memory.

In short, this isn't something you (generally) need to worry about. What is the problem you are trying to solve?

Brannon
I know what committed and reserved mean. The problem is that users often complain about high memory usage of .NET applications, and I want to somehow hide this.
wj32
The user should care about physical memory usage ( committed ), and not reserved, you usually start caring about reserved memory when you have high memory pressure, or when you run of virtual address space.The process can just reserve 1 GB of memory with ZERO effect on performance.
mfawzymkh
+3  A: 

The simplest answer is you can't. The .Net GC is self tuned, it reserve memory eagerly, however it doesn't commit memory until it is needed, when the memory is no longer needed, it is changed to reserved again.

The GC uncommit memory when there are high memory pressure on the machine.

33 MB is not that big, since by default ( if your process is 32 bit and you are running workstation GC mode ), you will have a default segment reserved for the small object heap that is 16 MB.

mfawzymkh