简体   繁体   English

在.NET中,GC.MaxGeneration是不是2?

[英]In .NET, Is GC.MaxGeneration Ever Not 2?

As far as I understand it, there are three generations of garbage collection - 0, 1 and 2, for all versions of .NET. 据我所知,对于所有版本的.NET,有三代垃圾收集 - 0,1和2。

Are there any circumstances where examining GC.MaxGeneration would yield anything other than 2? 是否有任何情况下检查GC.MaxGeneration会产生2以外的任何其他内容? Are there GCs on other frameworks that have a different number of GC generations? 在具有不同GC生成数的其他框架上是否有GC?

It should be noted that GC.MaxGeneration being constant for the application's lifetime is in itself an implementation detail: 应该注意的是, GC.MaxGeneration对于应用程序的生命周期来说是常量,本身就是一个实现细节:

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. 对于此实现, MaxGeneration属性返回的值保证在执行的应用程序的生命周期内保持不变。

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). 这意味着MaxGeneration不仅可以在.NET框架的其他实现中与2不同,而且在程序执行期间也可能不同 (取决于调用属性getter时垃圾收集器使用的代数)。

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). 例如,Mono可以使用Boehm非代际GCMaxGeneration将始终为0 ),或者SGen代GC (仅实现两代,因此MaxGeneration将始终小于或等于1 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM