Debugging memory leaks using crtdbg.h

Started by
3 comments, last by hymerman 18 years, 2 months ago
I'm trying to clean up my program's act using crtdbg.h as suggested by MSDN, but it's not working as they said it would (why isn't anything ever simple?). Instead of displaying the line number of my files where the memory is allocated, it's displaying the line number in crtdbg.h on which memory is allocated (line 1147), which is of no help whatsoever. What on earth could I be doing wrong? I've done everything exactly as they've said. Here's the article, should you wish to read it: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsdebug/html/vxconenablingmemoryleakdetection.asp
Advertisement
Looks like it only works for malloc with the stuff they give;

malloc:
Detected memory leaks!Dumping objects ->c:\documents and settings\blah\my documents\visual studio 2005\projects\xyz\xyz\Core.cpp(15) : {53} normal block at 0x00354C50, 32 bytes long. Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD Object dump complete.


new:
Detected memory leaks!Dumping objects ->c:\program files\microsoft visual studio 8\vc\include\crtdbg.h(1150) : {53} normal block at 0x00354C50, 32 bytes long. Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD Object dump complete.


P.S.

I used this:
#ifdef _DEBUG#define _CRTDBG_MAP_ALLOC#include <stdlib.h>#include <Crtdbg.h>#endif...char * pszBuffer = static_cast <char *> (malloc(32));//char * pszBuffer = new char[32];#ifdef _DEBUG_CrtDumpMemoryLeaks();#endif...


Quote:
By including crtdbg.h, you map the malloc and free functions to their Debug versions, _malloc_dbg and _free_dbg, which keep track of memory allocation and deallocation.


Maybe it just doesn't support new / delete?
Use the Fluid Studios memory manager. Its extremely simple and powerful. All you have to do is include the header and source and it automatically detects all leaks, and even provides a report on all allocations. Plus, its 100% free.

http://www.fluidstudios.com/pub/FluidStudios/MemoryManagers/Fluid_Studios_Memory_Manager.zip
Mike Popoloski | Journal | SlimDX
Nice tool, thanks ussnewjersey4.
Indeed, that's working a load better. Now, if only I knew how to fix the leaks it's reporting...

This topic is closed to new replies.

Advertisement