Sign in to follow this  

Debugging memory leaks using crtdbg.h

This topic is 4335 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

This topic is 4335 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this