Home All Groups Group Topic Archive Search About

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

Author
4 Jan 2007 10:36 AM
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!

Author
4 Jan 2007 2:10 PM
Bruno van Dooren [MVP VC++]
> 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!

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.

--
Kind regards,
    Bruno.
    bruno_nos_pam_van_doo***@hotmail.com
    Remove only "_nos_pam"
Author
4 Jan 2007 3:30 PM
Ben Voigt
Show quote
"Bruno van Dooren [MVP VC++]" <bruno_nos_pam_van_doo***@hotmail.com> wrote
in message news:B97B243B-92B5-460E-80AC-CBC62D12907C@microsoft.com...
>> 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!
>
> 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.

Show quote
>
> --
> Kind regards,
>    Bruno.
>    bruno_nos_pam_van_doo***@hotmail.com
>    Remove only "_nos_pam"
>
Author
11 Jan 2007 4:33 AM
Surain
Show quote
"Ben Voigt" <rbv@nospam.nospam> wrote in
news:epsSyUBMHHA.3312@TK2MSFTNGP03.phx.gbl:

>
> "Bruno van Dooren [MVP VC++]" <bruno_nos_pam_van_doo***@hotmail.com>
> wrote in message
> news:B97B243B-92B5-460E-80AC-CBC62D12907C@microsoft.com...
>>> 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!
>>
>> 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?

AddThis Social Bookmark Button