在每天运行24小时的应用程序中使用GC.Collect是否明智? [英] is it smart to use GC.Collect on application that runs 24h per day?

查看:349
本文介绍了在每天运行24小时的应用程序中使用GC.Collect是否明智?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的应用程序每天运行24小时,每周运行7天。有时CPU会达到100%,然后回到80%。与RAM相同。在几个小时后手动调用 GC.Collect 或自动离开它是明智之举



我们使用C# 2010年,SQL 2008和Fluent Nhiberanet。这是桌面应用程序。

解决方案

调用 GC.Collect() 每隔几个小时,或者当内存使用率变高时,但我会称它为聪明的,只要你处于比GC更多的信息的位置,就可以称它为一些例子




  • 你知道,这块很大的内存或者刚刚分配的很多小对象不会再被使用并且你处于一个单线程环境中,并且(当然)你已经清除了所有的引用。

  • 你知道,GC break现在会比稍后更少伤害



GC是一个高度优化的代码,非常聪明,但它只能处理它拥有的信息。


We have application that runs 24h per day and 7 days per week. Sometimes CPU go to 100% and then go back to 80%. The same with RAM. Is it smart to manually call GC.Collect after few hours or betterto leave it automatically.

We are using C# 2010, SQL 2008 and Fluent Nhiberanet. This is desktop application.

解决方案

I wouldn't call it smart to call GC.Collect() "every few hours", or "when RAM usage goes to high", but I'd call it smart to call it whenever you are in a position of having more information than the GC, some exmaples

  • You know, this big chunk of RAM or these many small objects you just allocated, will not be used again and you are in a singlethreaded environment and (ofcourse) you have cleared all your references
  • You know, that a "GC break" will hurt less right now, than a bit later

The GC is a highly optimized peace of code and quite smart, but it can only work on information it has.

这篇关于在每天运行24小时的应用程序中使用GC.Collect是否明智?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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