如何在 Windows 上进行内存分析?
可能的重复:
Windows下C++的内存泄漏工具
我以前在 Mac 上工作我真正喜欢 XCode 的一件事是它的分析器。通过使用该探查器的各种设置运行我的程序,我发现了许多错误。最值得注意的是,它会向我显示程序的哪些部分消耗了内存,它会向我显示它是否泄漏内存,并且会向我显示何时会泄漏内存。如果我使用 GUI 应用程序,它甚至会向我显示发生这些分配/泄漏/解除分配时我正在执行的操作的屏幕截图。
现在,我正在使用 Visual Studio 开发一个 Windows/C++ 项目,我怀疑该项目消耗了太多内存,并且还可能泄漏一些内存。使用 XCode,我只需启动该分析器即可立即知道发生了什么。然而,在 Visual Studio 中,我找不到这样的东西(有一个有点尴尬的性能分析器,但 CPU 时间不是我关心的)。
那么,您将如何搜索内存消耗过多的泄漏和代码呢?
Possible Duplicate:
Memory leak tool for C++ under Windows
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.
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).
So, how would you go about searching for leaks and code with too much memory consumption?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请参阅应用程序验证程序、LeakDiag、UMDH 和一般来说,Windows 调试工具。
所有这些都是免费的。
有关如何使用它们的指南,请参阅高级 Windows 调试。
See Application Verifier, LeakDiag, UMDH, and Debugging Tools for Windows in general.
All of which are free.
For a guide on how to use them, see Advanced Windows Debugging.
VS 中没有用于非托管应用程序内存分析的内置工具。
对于其他第三方工具,请参阅这篇文章:
是否可以检测 GDI 泄漏Visual Studio 调试器?
There is no inbuilt tool in VS for memory profiling for unmanaged applications.
For other third party tools, see this post :
Is it possible to detect GDI leaks from the Visual Studio debugger?
我将从使用 Perfmon.exe 工具开始(只需在“运行”提示符下键入 perfmon.exe)。使用此工具,您可以添加“私有字节”、“句柄计数”、“线程计数”等计数器,以随时间分析您的应用程序。
使用此工具可以提取很多有趣的信息,MSDN 上有大量信息介绍如何使用它,它不仅限于内存泄漏,还可以对 I/O 性能和其他内容进行基准测试。
请记住,对于每种计数器类型,您都可以启用简短描述,概述计数器的用途(我认为其默认关闭)。
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.
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.
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).