Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tools for memory leak detection

Status
Not open for further replies.

globos

Programmer
Nov 8, 2000
260
FR
Hi,

Currently I am detecting memory leaks with a very basic mechanism which consists of the VC++ debugger and the C runtime debug heap functions.
I have to put these lines :
Code:
#define CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
at the begining of the file containing the main function of the source code to inspect.
Memory leaks are printed at the exit of the program by putting this instruction at the first line of the main :
Code:
//...
int main (int argc, char** argv)
{
  _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  //...
}

All of this is described at:


My question is : is there a free tool(or library) that works at a higher-level? I mean that at least tells where the memory leak occurs (the class for example).

--
Globos
 
If it is just C, you could try


If it is C++, just redefine the new and delete operators and relink them into your program. The new will allocate the memory and keep track of where it was allocated. The only problem is trying to figure out where new was being called from. You could save the stack address and then look it up in the map during the atexit phase.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top