什么时候GC决定收集第2代? [英] When does GC decide to collect generation 2?

查看:180
本文介绍了什么时候GC决定收集第2代?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

白天我看到了很多的Gen 2的集合在我们的windows服务。

During the day I see a lot of gen 2 collections in our windows service.

在没有GC决定这样做,而不是只收集Gen1和Gen0或全额征收只Gen0?

When does GC decide to do full collection instead of collecting only Gen1 and Gen0 or only Gen0?

推荐答案

读<一href="http://msdn.microsoft.com/en-us/library/0xy59wtx.aspx">http://msdn.microsoft.com/en-us/library/0xy59wtx.aspx并链接文章以获取更多信息。一般来说,第2代收集必要的时候。

Read http://msdn.microsoft.com/en-us/library/0xy59wtx.aspx and the linked articles for more information. In general, gen2 is collected "when necessary."

一件事,可能会导致过多的第2代的集合是大对象堆(LOH)。当蕙得到填补,这将触发一个完整的集合。如果您的应用程序分配和释放大量的大型对象(80K或更大),那很可能是你的问题。

One thing that can cause excessive Gen2 collections is the large object heap (LOH). When the LOH gets filled, it will trigger a full collection. If your application allocates and frees lots of large objects (80K or larger), that could very well be your problem.

请参阅 CLR内到外:大对象堆揭秘

也可以考虑使用服务器的垃圾收集器在您的服务。它通常会提供更好的性能(更少的集合)。添加到您的app.config文件:

Also consider using the server garbage collector in your service. It will typically provide better performance (fewer collections). Add this to your app.config file:

<configuration
   <runtime>
      <gcServer enabled="true"/>
   </runtime>
</configuration> 

这篇关于什么时候GC决定收集第2代?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆