抑制C#垃圾收集 [英] Suppressing C# garbage collection

查看:105
本文介绍了抑制C#垃圾收集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序分配了大量的内存(数百万个总计几千兆字节的小对象)并持续了很长时间。


  1. .NET是否浪费时间检查所有这些数据以进行GC操作?

  2. Gen 2 GC出现的频率(检查所有对象的频率)?

  3. 有什么办法可以减少频率或暂时抑制频率发生?

  4. 我准确地知道何时可以收集大量内存,有没有什么办法可以优化?我目前正在调用GC.Collect(); GC.WaitForPendingFinalizers();

更新:
Perf计数器%GC中的时间显示平均值为10.6%。<除非您可以确认垃圾回收器正在积极降低应用程序的性能,否则您不应该采取措施来削弱功能你的运行环境。



从你的问题来看,你还没有确认GC是一个问题。我严重怀疑它是什么。



仅优化需要优化的内容。


My application allocates a large amount of memory (millions of small objects totaling several gigabytes) and holds onto it for a long time.

  1. Is .NET wasting time checking through all of this data to do GC on it?
  2. How often does the Gen 2 GC occur (the one that checks all objects)?
  3. Is there any way to reduce it's frequency or temporarily suppress it from occurring?
  4. I know exactly when I am ready for a large amount of memory to be collected, is there any way to optimize for that? I am currently calling GC.Collect(); GC.WaitForPendingFinalizers(); at that time.

Update: Perf counter "% Time in GC" is showing an average of 10.6%.

解决方案

Unless you can confirm that the garbage collector is actively slowing the performance of your application, you should not take steps to cripple the functionality of your runtime environment.

Judging from your question, you have not confirmed that the GC is a problem. I severely doubt that it is.

Optimize only what needs to be optimized.

这篇关于抑制C#垃圾收集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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