Re: GC.Collect and Generations
- From: AJ <noone@xxxxxxxxxxx>
- Date: Wed, 2 Aug 2006 13:01:10 +0100
My understanding is...
GC.Collect() isn't special. It attempts to collect, and any remaining
objects will be upped into the next generation.
There aren't many cases when calling GC.Collect() is a good idea. Doing
so inside a loop sounds odd.
By the way, in your example code, the 'o' object will be collected on
the first call since it's no longer rooted... So it doesn't move up the
genreations..
In article <uSKQshgtGHA.1288@xxxxxxxxxxxxxxxxxxxx>, "Günter Prossliner"
<g.prossliner/gmx/at> says...
Hi everybody!.
As we all know, die Garbage Collector minimizes the time needed for a
collection by using generations. When an object remains uncollected, it
moves one generation up. Higher generations are not collected such often as
lower generations. When an object lives in the generation 2 (the highest in
the current implementation), garbage collection will - under most
circumstances - not happen (this is not documented, but it was pointed out
in some MSDN articles).
Ok.
What if the Developer calls GC.Collect()? I have seen code (not mine), where
GC.Collection was called even within loops! From my understanding this would
result in having object in high generations allthough they are not long
living (maybe just Objects that have a liftime within a simple method). This
would result in a very high memory foodprint, since this objects will not
(or very seldom) get collected.
Or does the GC handle calls to GC.Collect() special? I meen that objects are
not moved into a higher Generation?
c# sample:
void foo(){
SmallMethod();
GC.Collect(); // o will move in gen #1
GC.Collect(); // o will move in gen #2
}
void SmallMethod(){
VeryBigManagedObject o = new VeryBigManagedObject();
}
br GP
- Follow-Ups:
- Re: GC.Collect and Generations
- From: Günter Prossliner
- Re: GC.Collect and Generations
- References:
- GC.Collect and Generations
- From: Günter Prossliner
- GC.Collect and Generations
- Prev by Date: Executing GC.Collect and GC.WaitForPendingFinalizers
- Next by Date: Re: GC.Collect and Generations
- Previous by thread: GC.Collect and Generations
- Next by thread: Re: GC.Collect and Generations
- Index(es):
Relevant Pages
|