.Net 垃圾收集器 - 查看运行时期间升级到 Gen2 的内容
我的程序正在以非常高的速率(大约 1MB/秒)将内存提升到 Gen2,并且在发生 Gen2 收集时会导致性能下降。 我试图了解哪些对象被升级的每次尝试都失败了 - 主要是因为当我在 Windbg 中打开 2 个转储时,构成 Gen2 大小增加的内存被标记为“空闲”。 这让我怀疑固定对象导致了问题,但 perfmon 统计数据显示固定对象的数量非常低(大约 2-4)。
我现在正在考虑尝试以某种方式确定哪些对象在运行时升级到 Gen2。 有没有办法做到这一点?
My program is promoting memory to Gen2 at a very high rate (about 1MB/Sec) and it causes performance hit when Gen2 collection occurs.
Every attempt I made to understand which objects were promoted failed - mainly due to the fact that when I opened 2 dumps in windbg, the memory from which the increase of Gen2 size was made up, was marked as "Free".
It led me to suspect that Pinned objects are causing the problem but perfmon statistics shows that # of Pinned objects is very low (about 2-4).
What I'm thinking about trying now is to somehow identify which objects are promoted to Gen2 in runtime.
Is there a method for doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用 WinDbg 来调试此类问题。在垃圾收集例程上设置一个断点,检查托管堆,让垃圾收集发生,然后再次检查托管堆以查看哪些对象现在位于 Gen2 中。
以下是一些可以开始的链接:
跟踪托管内存泄漏
如何迭代.NET 托管堆中存在的对象?
Tess Ferrandez 的博客
调查 .NET内存管理和垃圾收集
抱歉,这不是对您的问题的直接、详细的回答,但它应该为您提供一个起点。
You could use WinDbg to debug such issues. Set a breakpoint on the garbage collection routine, examine the managed heap, let the garbage collection occur, then examine the managed heap again to see which objects are in Gen2 now.
Here are some links to start with:
Tracking down managed memory leaks
How to iterate on the objects present in the .NET managed heap?
Tess Ferrandez' blog
Investigating .NET Memory Management and Garbage Collection
Sorry that's not an direct, detailed answer to your question, but it should give you a starting point.
有一些 3 方 .NET 内存分析器,尝试一下,大多数都允许您免费试用期。我希望任何领先的内存分析器都能让您快速了解正在发生的情况。
There are a few 3 party memory profilers for .NET, give them a try, most of them allow you a free trial period. I expect any of the leading memory profilers will let you see what is going on quickly.
您可能会分配大量 LOH。这是一种在 LOH 分配上设置断点的方法。
Winbdg 中的
bp mscorwks!wks::gc_heap::allocate_large_object “!CLRStack”
。华泰
You could be allocating a lot of LOH. Here is a way to have a break-point on LOH allocation.
bp mscorwks!wks::gc_heap::allocate_large_object “!CLRStack”
within Winbdg.HTH
您可以尝试强制 gen(0) 和 gen(1) 收集,并在运行完成后立即拍摄快照
另外,您使用哪种 GC 风格?
You could try forcing gen(0) and gen(1) collections and take a snapshot immediately after it finishes running
Also, what kind of GC flavour are your using?