简体   繁体   English

.Net垃圾收集器 - 查看运行时期间提升为Gen2的内容

[英].Net Garbage Collector - See what is promoted to Gen2 during Runtime

My program is promoting memory to Gen2 at a very high rate (about 1MB/Sec) and it causes performance hit when Gen2 collection occurs. 我的程序以非常高的速率(大约1MB /秒)向Gen2提升内存,并且当Gen2收集发生时它会导致性能损失。 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". 我为了解哪些对象被提升而做出的每一次尝试都失败了 - 主要是因为当我在windbg中打开2个转储时,Gen2大小增加的内存被标记为“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). 这让我怀疑Pinned对象引起了问题,但是perfmon统计数据显示固定对象的数量非常低(大约2-4)。

What I'm thinking about trying now is to somehow identify which objects are promoted to Gen2 in runtime. 我现在正在考虑的是以某种方式识别哪些对象在运行时被提升为Gen2。 Is there a method for doing this? 有这样做的方法吗?

You could use WinDbg to debug such issues. 您可以使用WinDbg来调试此类问题。 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. 在垃圾收集例程上设置断点,检查托管堆,发生垃圾收集,然后再次检查托管堆以查看Gen2中的哪些对象。

Here are some links to start with: 以下是一些开头的链接:

Tracking down managed memory leaks 追踪托管内存泄漏

How to iterate on the objects present in the .NET managed heap? 如何迭代.NET托管堆中存在的对象?

Tess Ferrandez' blog 苔丝费兰德斯的博客

Investigating .NET Memory Management and Garbage Collection 研究.NET内存管理和垃圾收集

Sorry that's not an direct, detailed answer to your question, but it should give you a starting point. 对不起,这不是你的问题的直接,详细的答案,但它应该给你一个起点。

There are a few 3 party memory profilers for .NET , give them a try, most of them allow you a free trial period. .NET有一些3方内存分析器 ,试一试,大多数允许你免费试用期。 I expect any of the leading memory profilers will let you see what is going on quickly. 我希望任何领先的内存分析器都能让你快速了解正在发生的事情。

You could be allocating a lot of LOH. 你可能会分配很多LOH。 Here is a way to have a break-point on LOH allocation. 这是一种在LOH分配上有一个断点的方法。 bp mscorwks!wks::gc_heap::allocate_large_object “!CLRStack” within Winbdg. bp mscorwks!wks::gc_heap::allocate_large_object “!CLRStack”在Winbdg中。

HTH HTH

You could try forcing gen(0) and gen(1) collections and take a snapshot immediately after it finishes running 您可以尝试强制gen(0)和gen(1)集合,并在完成运行后立即拍摄快照

GC.Collect(1,GCCollectionMode.Forced);
GC.WaitForPendingFinalizers();
CreateDump();

Also, what kind of GC flavour are your using? 另外,你使用什么样的GC风味?

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

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