when will .net application free the committed memory (or VM)

  • Thread starter Thread starter Surain Shen
  • Start date Start date
S

Surain Shen

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!
 
Bruno van Dooren said:
If no reference to the piece of memory is in scope anymore, the GC marks
the
memory as being ready for disposal.
If the GC decides it is time to release it, it will actually dispose of
it,
but you don't know exactly when that is. It may do it immediately, in 5
minutes or never.
You will never know deterministically when this will happen.

The only thing you can do is to explicitly trigger a GC cycle, but that
will
perform a complete garbage collection across everything that is marked
disposable.

That still may not give the unused memory back to the OS. Short of using
VirtualAlloc and VirtualFree to manage buffers, I guess the only guarantee
is that all resources are reclaimed when the process ends.
 
"Bruno van Dooren [MVP VC++]" <[email protected]>
wrote in message
If no reference to the piece of memory is in scope anymore, the GC
marks the
memory as being ready for disposal.
If the GC decides it is time to release it, it will actually dispose
of it,
but you don't know exactly when that is. It may do it immediately, in
5 minutes or never.
You will never know deterministically when this will happen.

The only thing you can do is to explicitly trigger a GC cycle, but
that will
perform a complete garbage collection across everything that is
marked disposable.

That still may not give the unused memory back to the OS. Short of
using VirtualAlloc and VirtualFree to manage buffers, I guess the only
guarantee is that all resources are reclaimed when the process ends.

I do think so, but it seems that GC really do free memory back to the OS,
otherwise the memory usage of .net app will not decrease during running!

My question is when will the GC decide to free memory back to the OS?
 
Back
Top