![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
|
It's known, that .net app alloctes a block of memory and managed itselsf (or by GC), and when gc do collect, it may not free the committed memory immediately. Who'd like tell me when will it REALLY free the memory. Any reply is highly appreciated! |
#2
| |||
| |||
|
|
"Surain Shen" <looong.shin (AT) gmail (DOT) com> wrote in message news:%23KFq9w%23LHHA.420 (AT) TK2MSFTNGP06 (DOT) phx.gbl... It's known, that .net app alloctes a block of memory and managed itselsf (or by GC), and when gc do collect, it may not free the committed memory immediately. Who'd like tell me when will it REALLY free the memory. Any reply is highly appreciated! It's important to understand the role of the GC, the GC is not a memory allocator, it's a private heap manager, it controls and manages the "managed" object allocations by collecting and compacting the generational heap(s), but the heap "segments" allocated from the process heap are not under control of the GC, this is the task of the CLR's memory allocator. Without going too much in detail here is what happens, at the start, the CLR (memory allocator) reserves two segments for the GC heaps (one for gen0, 1 , 2 and one for the Large Object heap) from the OS, both of these segments are 16MB in size for the WKST version of the CLR and two times 32 MB for the server version. When a new object allocation hits a guard page in it's current segment, the GC will force a collect/compactation run, and if after this run, the object allocation still hits the guard page, then will the GC request the CLR for more memory, and the CLR memory manager will request the OS for another segment of 16 or 32 MB. The GC can continue to allocate objects from this new heap segment. If after this, it happens that all objects are moved back to the initial segments after a GC compactation run, the memory allocator is free to return that segment to the OS. Whether this happens depends on a number of heuristics, like memory pressure GC type and object allocation/de-allocation frequency, in general the memory allocator does return the excess segments unless it is requested by the OS memory manager, or when a memory threashold is reached. Willy. |
#3
| |||
| |||
|
|
Hi, Willy, Thx a lot for ur reply, I do think it hits my question well ![]() There is a further question, but first pls have a glance at my story: I had a winform app which consume much more memory than a similar app of the competitor which looks written by VC. Compare the "VM Size" and "Mem Usage" measure value in the task manager, my app always be twice over the competitor's. As a result, the customer ask us to try decrease the memory usage to a reasonable range, otherwise ... |
|
I had tried to do somethings such as releasing the reference, disposing, and I even find anonymous method will increase memory usage a bit, and etc., but it seems the memory usage only decrease a little... Ok, my final question is how can I decrease the memory usage obviously? |
|
Of course, I and my customer known that .Net app will consume more memory than the similar app which written by VC. We still hope to improve that problem. What problem? It's not difficult to consume a lot more memory when coding in a managed OO |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |