1

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

Addition

Here it is:

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

Travis Banger
  • 697
  • 1
  • 7
  • 19
  • 1
    http://stackoverflow.com/questions/413477/is-there-a-good-valgrind-substitute-for-windows#413842 – Mitch Wheat Jan 26 '14 at 00:52
  • 1
    There are too many ways to do this to answer your question directly, particularly since there is no detail regarding what you're actually *doing*. A native WINAPI-only application that doesn't use the CRT whatsoever would find CRT-debug-heap services pretty useless. Using WinDbg and the global/local WIN32 heap facilities would be pretty useless if you're using a sub allocation library (like many CRTs employ). You're probably better off searching this site for answers that best-match your particular usage. I can all-but-guarantee its covered *somewhere*. – WhozCraig Jan 26 '14 at 00:58
  • 2
    Most likely this is what you mean http://msdn.microsoft.com/en-us/library/x98tx3cf.aspx – brian beuning Jan 26 '14 at 01:02
  • I posted the question in the C++ groups. I guess I should have added that detail in the question itself. I should have also mentioned that it is a Microsoft tool. – Travis Banger Jan 26 '14 at 01:03

1 Answers1

1

The debug C run-time library with Visual Studio can track all allocations and automatically report any that aren't freed at application exit. 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:

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

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.

Adrian McCarthy
  • 45,555
  • 16
  • 123
  • 175