简体   繁体   中英

What tools and techniques can I use to detect and isolate high memory usage in .NET applications which call into significant unmanaged code?

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.

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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