VS2012, C++11 and memory leak detection (VLD vs CRTDBG)

c++, c++11, memory-leaks, visual-studio-2012

Solution

If you have some global objects or something on the stack in `main()`, they won't be destroyed before the `main()` exits.

If these objects do dynamic memory allocation and you call `_CrtDumpMemoryLeaks()` at the very end of the `main()`, you will still see that memory as "leaked."

Problem

I had a bunch of memory leaks detected with CRTDBG but found them difficult to trace so installed Visual Leak Detection. This showed a consistent number of leaks which I traced to abstract classes not having virtual destructors. I fixed this and VLD now shows no memory leaks in my application, however CRTDBG still does and it's showing consistently around 100 or so leaks. Can either of these tools be trusted with C++11? I'm heavily using unique pointers and barely making any new objects without them so can't understand where the leaks are coming from.

Original source