简体   繁体   English

Windows Development:如何确定我的应用程序是否正在泄漏内存?

[英]Windows Development: How to determine whether my app is leaking memory?

A long time ago I was told about some statement that you add at the beginning of the application and when it is done, the facility informs whether the app has unreclaimed memory. 很久以前,有人告诉我您在应用程序的开头添加了一些语句,完成后,该工具会通知应用程序是否有未回收的内存。

TIA TIA

Addition 加成

Here it is: 这里是:

http://msdn.microsoft.com/en-us/library/e5ewb1h3%28v=vs.80%29.aspx http://msdn.microsoft.com/en-us/library/e5ewb1h3%28v=vs.80%29.aspx

The debug C run-time library with Visual Studio can track all allocations and automatically report any that aren't freed at application exit. 带有Visual Studio的调试C运行时库可以跟踪所有分配,并自动报告在应用程序退出时未释放的所有分配。 First, include <crtdbg.h> , and then at the very beginning of your program, ask it to track allocation and report leaks by making this call: 首先,包括<crtdbg.h> ,然后在程序的最开始,通过进行以下调用来要求它跟踪分配并报告泄漏:

_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);

In the debug output window of the Visual Studio debugger (or another program that monitors the debug output), you'll see a report of leaked allocations when the application ends. 在Visual Studio调试器(或监视调试输出的另一个程序)的调试输出窗口中,您将在应用程序结束时看到泄漏分配的报告。

In general, you probably only want to do this in a debug build, as there is a nontrivial performance impact. 通常,您可能只想在调试版本中执行此操作,因为这会对性能产生不小的影响。

Also note that if you allocate singletons and never free them, they will (not surprisingly) be reported as leaks. 还要注意,如果您分配单例并且从不释放它们,它们(毫无意外地)将被报告为泄漏。

Full details are in MSDN. 详细信息在MSDN中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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