hey i am trying to detect leaks in visual studio using :
#define _CRTDBG_MAPALLOC
#include <stdlib.h>
#include <crtdbg.h>
and in the end of the main i am typing :
_CrtDumpMemoryLeaks();
when i do all of this i am getting the the memoryleaks (what inside them) but not the places that the allocates were made , can u please help me with the command that show where were the allocated been made , thanks in advance.
You can’t out of the box. CrtDumpMemoryLeaks only tells you if there are any memory leaks, not where the memory leak is. The CRT provides no such facility.
There are a couple of ways to accomplish something like this. One way would be to use a tool like Valgrind, which instruments the entire application and runs the application inside a Virtual Machine. Valgrind severely slows down the application but makes this kind of analysis possible. The CRT doesn’t have the luxury of running things in a virtual machine, so it can’t really provide information like this.
Another way would be to use smarter debuggers that understand the heap allocation path and that track every allocation for you, as Aaron Klotz’s documents in his answer.
Oh, one more thing — if you’re using memory correctly in C++, you shouldn’t ever be having to worry about memory leaks because you shouldn’t be
deleteing memory manually. Consider wrapping any calls tonewusing various smart pointer types instead.