As far as I understand it, there are three generations of garbage collection - 0, 1 and 2, for all versions of .NET.
Are there any circumstances where examining GC.MaxGeneration
would yield anything other than 2? Are there GCs on other frameworks that have a different number of GC generations?
It should be noted that GC.MaxGeneration being constant for the application's lifetime is in itself an implementation detail:
Notes to Implementers
For this implementation, the value returned by the
MaxGeneration
property is guaranteed to remain constant for the lifetime of an executing application.
This implies that not only can MaxGeneration
be different from 2
in other implementations of the .NET framework, but it can also vary during program execution (depending on the number of generations used by the garbage collector at the time the property getter is called).
Other implementations can also use different garbage collectors depending on the circumstances. For instance, Mono can either use the Boehm non-generational GC (MaxGeneration
will always be 0
then), or the SGen generational GC (which only implements two generations, so MaxGeneration
will always be less than or equal to 1
there).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With