V
Vladimir
Hello, All!
When I should call GC.Collect() to force garbage collection?
Regards,
Vladimir.
Winamp 5.0 (not active)
When I should call GC.Collect() to force garbage collection?
Regards,
Vladimir.
Winamp 5.0 (not active)
Vladimir said:Hello, All!
When I should call GC.Collect() to force garbage collection?
Vladimir said:Hello, All!
When I should call GC.Collect() to force garbage collection?
Regards,
Vladimir.
Winamp 5.0 (not active)
Daniel said:General rule: Never.
Advanced rule: if, and only if, you release a huge amount of
resources(maybe a very large object tree), calling GC.Collect()
*might* help you by releasing memory faster, but there is no guarentee
that it actually will.
011 said:Hello, Daniel!
You wrote on Sat, 13 Mar 2004 01:29:43 -0600:
DOC> General rule: Never.
DOC> Advanced rule: if, and only if, you release a huge amount of
DOC> resources(maybe a very large object tree), calling
DOC> GC.Collect() *might* help you by releasing memory faster,
DOC> but there is no guarentee that it actually will.
I've developed not very complex console app in C# that realizes some math
algorithm with many memory allocations using "new" operator. I have some
custom collections derived from System.Collections.CollectionBase. I
thought that memory would be released when collection object goes out of
scope. But MSDN says that garbage collection process is being initiated
when there is no free memory for allocation.
Well I've decided to place two Console.ReadLine() calls at the very
beginning and two calls at the very end of Main proc (see below) to see
how much memory is used through Task Manager (not using debugging).
static int Main()
{
Console.ReadLine(); // here we have 4480 KB used
<do some math & memory allocation>
Console.ReadLine(); // 5184 KB used
GC.Collect();
Console.ReadLine(); // 5184 KB used (again!)
return 0;
}
Well I'm surprised that at the beginning of execution there is almost 4.5
MB used. Is that a "feature" of managed apps?
And GC does nothing. Why?