-->

How to do memory profiling on Windows? [duplicate]

2020-02-26 11:22发布

问题:

This question already exists:
Closed 9 years ago.

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?

回答1:

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.



回答2:

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?



回答3:

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).