简体   繁体   中英

Debug High Memory Usage

What are good tools/techniques for discovering which areas of the code are using a lot of memory? I've seen similar questions for linux that mention valgrind, but not one for a windows application developed with Visual Studio 2010.

There is also AQTime which can give you a list of allocated objects and a call-stack of where each object was created if you use the allocation profiler.

Other options include manually instrumenting your code with instance counters for your objects to your code. Not ideal but it can be useful especially if the profiling tool fails to run your application (eg due to low memory or instrumentation failures etc).

What these tools often don't usually show in a very obvious way is memory fragmentation - which can easily occur if you have lots of large objects and lots of small objects being allocated and freed frequently in differing orders. It can be worth using pools for some of these objects if possible and it can have drastic effects on memory usage and also performance in some situations.

The Microsoft CRT included with VS2010 has strong support for leak detection built in. Available in the crtdbg.h header, enabling it is described well in this MSDN library article .

If that's too much hardship then the Debugging Tools for Windows package can be very useful. The UMHD (User Mode Heap Debugger) utility can report leakage without changing your program.

The Performance Wizard allows a very detailed view of resource utilization and can highlight single lines of code which lead to a high memory load. To start the wizard, click on the Analyze menu of Visual Studio and then on Launch Performance Wizard. A premium version or higher may be required to run the full examination.

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