Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 433
Rajveer Avatar asked Jan 27 '13 14:01

Rajveer


1 Answers

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

like image 98
Ali Avatar answered Oct 05 '22 23:10

Ali