detecting memory leaks

Started by
4 comments, last by graeme 22 years, 1 month ago
can anyone recommend shareware which detects memory leaks in a program?
Advertisement
Visual C++
The Ubiquitous Book-CDRom Compiler - Vis C++
hi, how do you enable ms visual C++ to detect memory leaks?
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
I''m sure there are plenty of free (or shareware) leak detectors (hint: search google). One option is using the Boehm-Demers-Weiser garbage collector in leak detection mode.

Link: Boehm-Demers-Weiser Garbage Collector.
To enable memory-checking in VC++ add the following at the start of your main-function:

        #ifndef NDEBUGint flag = _CrtSetDbgFlag (_CRTDBG_REPORT_FLAG);flag |= _CRTDBG_LEAK_CHECK_DF;_CrtSetDbgFlag (flag);#endif  


The #ifndef NDEBUG ensures that memory-checking is only enabled when you do debug-runs.
You also need to include the crtdbg.h file.

Unfortunately, with this setup you will only be told the size of the leak and a rather inscrutable hex-code.
You can, however, add the following code to your program (before your functions):


  #ifndef NDEBUG#define new new (_NORMAL_BLOCK, __FILE__, __LINE__)#define malloc(size) _malloc_dbg(size, _NORMAL_BLOCK, __FILE__, __LINE__)#endif        


Neophyte

- Death awaits you all with nasty, big, pointy teeth. -

EDIT: Formatting
EDIT2: Formatting(again)
EDIT3: Formatting (yet again. Goddamn).

[edited by - Neophyte on March 21, 2002 12:43:38 AM]

[edited by - Neophyte on March 21, 2002 12:44:18 AM]

[edited by - Neophyte on March 21, 2002 12:45:24 AM]

This topic is closed to new replies.

Advertisement