我可以使用哪些工具和技术来检测和隔离 .NET 应用程序中调用重要非托管代码的高内存使用率?

发布于 2024-07-12 11:21:41 字数 727 浏览 8 评论 0原文

假设我有一个用 C# 编写的 WinForms .NET 应用程序。 该应用程序从托管堆和非托管堆中分配大量内存。 我可以(相对)轻松地使用 Red Gate ANTS Profiler(我没有使用过)或 JetBrains dotTrace

我遇到麻烦的地方是当托管对象使用大量本机资源(例如图像或大型 COM 对象)时,或者当我调用具有大量内存需求的非托管第三方库时。 到目前为止,我确实需要做一些侦探工作来弄清楚:1)是托管代码还是非托管代码占用了内存;2)谁使用了这么多非托管堆。

目前我拥有的唯一技术是在 perfmon 中设置性能计数器,以比较托管堆与非托管堆的大小、分配等。如果非托管堆继续增长而托管堆稳定,我知道要开始查看消耗本机资源的非托管库和/或 .NET 对象。

帮助开发人员处理大量托管非托管代码的工具和技术的最佳组合是什么?

更新:更清楚地说,我想知道如何检测从托管代码调用的非托管代码中的内存问题(高使用率、泄漏)。 我相信,像 dotTrace 这样的产品只能跟踪托管对象。

Suppose I have a WinForms .NET application written in C#. This application allocates large amounts of memory from both the managed and unmanaged heaps. I can (relatively) easily figure out the allocation details (who, when, how much, etc.) of the managed objects using tools like Red Gate ANTS Profiler (which I have not used) or JetBrains dotTrace.

Where I run into trouble is when the managed objects use significant native resources (Image for example, or large COM objects) or when I call out to unmanaged third party libraries with significant memory needs. Thus far I really have to do some detective work to figure out 1) is it the managed or unmanaged code that is the memory hog and 2) who is using so much of the unmanaged heap.

The only technique I have at the moment is to set performance counters in perfmon that compare the managed vs. unmanaged heap sizes, allocations, etc. If the unmanaged heap continues to grow while the managed heap is steady, I know to start looking at the unmanaged libraries and/or .NET objects that consume native resources.

What is the best combination of tools and techniques to help developers with significant amounts of managed and unmanaged code?

UPDATE: To be more clear, I would like to know how to detect memory problems (high usage, leaks) in unmanaged code being called from managed code. Products like dotTrace, I believe, only track managed objects.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

哆啦不做梦 2024-07-19 11:21:41

您可以使用与 .net 应用程序兼容的众多内存分析工具中的任何一个。
其中一些如下:

1).NET Profiler API

2)< a href="http://www.jetbrains.com/profiler/index.html" rel="nofollow noreferrer">dotTRACE Profiler

3)内存分析器

You can use any of the many memory profiling tools compatible with .net applications.
Some are as follows:

1).NET Profiler API

2)dotTRACE Profiler

3)Memory Profiler

栖竹 2024-07-19 11:21:41

您只需查看 Perfmon 中提供的许多 .NET 内存计数器即可获得概览。

如果您想使用免费工具,Windows 调试工具 (特别是 WinDbg + SoS)可以告诉您为什么对象没有按预期被收集。

You can get an overview by simply looking at the many .NET memory counters available in Perfmon.

If you want to use a free tool, Debugging Tools for Windows (specifically WinDbg + SoS) can tell you why objects are not being collected as expected.

魄砕の薆 2024-07-19 11:21:41

内存验证器可以告诉您有关您的非托管(本机)分配内存的所有信息.Net 应用程序或混合模式 .Net 应用程序或本机应用程序。

Memory Validator can tell you all about the unmanaged (natively) allocated memory in your .Net application or a mixed mode .Net application or a native application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文