visual-studio 如何在 Windows 上进行内存分析?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4322678/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to do memory profiling on Windows?
提问by bastibe
Possible Duplicate:
Memory leak tool for C++ under Windows
可能的重复:
Windows 下 C++ 的内存泄漏工具
I used to work on a Mac project and one thing I really enjoyed about XCode was its profiler. I found many a bug by just running my program with various settings of that profiler. Most notably, it would show me which parts of my program consumed memory, it would show me if it leaked memory and it would show me when it would do that. If I was working with a GUI application, it would even show me screenshots of what I was doing when those allocations/leaks/deallocations occurred.
我曾经从事过一个 Mac 项目,我真正喜欢 XCode 的一件事是它的分析器。通过使用该分析器的各种设置运行我的程序,我发现了许多错误。最值得注意的是,它会告诉我我的程序的哪些部分消耗了内存,它会告诉我它是否泄漏了内存,它会告诉我它何时会泄漏。如果我正在使用 GUI 应用程序,它甚至会向我显示发生这些分配/泄漏/解除分配时我正在做什么的屏幕截图。
Nowadays, I am working on a Windows/C++ project using Visual Studio and I suspect the project to consume too much memory and possibly leak some memory, too. Using XCode, I would just fire up that profiler and immediately know what's happening. In Visual Studio however, I can find no such thing (there is a somewhat awkward performance profiler, but CPU time is not my concern here).
现在,我正在使用 Visual Studio 处理 Windows/C++ 项目,我怀疑该项目消耗了太多内存并可能泄漏一些内存。使用 XCode,我只需启动分析器即可立即知道发生了什么。然而,在 Visual Studio 中,我找不到这样的东西(有一个有点笨拙的性能分析器,但在这里我不关心 CPU 时间)。
So, how would you go about searching for leaks and code with too much memory consumption?
那么,您将如何搜索内存消耗过多的泄漏和代码?
回答by Alex Budovski
See Application Verifier, LeakDiag, UMDH, and Debugging Tools for Windowsin general.
一般请参阅Application Verifier、LeakDiag、UMDH 和Debugging Tools for Windows。
All of which are free.
所有这些都是免费的。
For a guide on how to use them, see Advanced Windows Debugging.
有关如何使用它们的指南,请参阅高级 Windows 调试。
回答by ROAR
I would start with using the Perfmon.exe tool (just type perfmon.exe at the "run" prompt). With this tool you can add counters like "Private bytes", "Handle count" , "Thread count" etc for profiling your application over time.
我将从使用 Perfmon.exe 工具开始(只需在“运行”提示下键入 perfmon.exe)。使用此工具,您可以添加诸如“私有字节”、“句柄计数”、“线程计数”等计数器,以便随时间分析您的应用程序。
There is allot of interesting information that can be extracted using this tool and there is plenty of information on MSDN that covers how to use it, its not only limited to memory leaks, it can benchmark I/O performance and other stuff as well.
使用此工具可以提取很多有趣的信息,MSDN 上有大量信息介绍了如何使用它,不仅限于内存泄漏,它还可以对 I/O 性能和其他内容进行基准测试。
Remember that for each counter type you can enable an short description that will outline the purpose of the counter (I think its default off).
请记住,对于每种计数器类型,您都可以启用一个简短的描述来概述计数器的用途(我认为它的默认值是关闭的)。
回答by Madhur Ahuja
There is no inbuilt tool in VS for memory profiling for unmanaged applications.
VS 中没有用于对非托管应用程序进行内存分析的内置工具。
For other third party tools, see this post : Is it possible to detect GDI leaks from the Visual Studio debugger?
对于其他第三方工具,请参阅此帖子: 是否可以从 Visual Studio 调试器检测 GDI 泄漏?

