_CRTDBG_MAP_ALLOC Flag to find memory leaks

comptebidon81
comptebidon81 used Ask the Experts™
on
Hi!
I've got some nasty memory leaks that I have been trying to find for a while. I'm using Visual C++ 6.0, and I just discovered that in debug mode, it lists the leaking memory zones after the program is closed.
I've been looking around on msdn, and found out about a flag (_CRTDBG_MAP_ALLOC) that supposedly associates the faulty code with the leak. The problem is (providing I am right about this flag) I can't compile with this flag on!
I get this error:
error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined
Anybody knows how to make this work, or how to better find the memory leaks?
Oliver
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

 _CRTDBG_MAP_ALLOC  ... did you put this flag in Stdafx.h?

Author

Commented:
Well it did compile when I put the flag in Stdafx.h, but it doesn't seem to work. I still can't find the faulty line in the debugger window. Anyone knows how to find those leaks?
Oliver
jkr
Top Expert 2012

Commented:
What error exactly are you getting?

BTW, if this is for testing purposes only, you might want to try the "Force File Output" option in the linker settings. Be sure to remove that for a release build.
Expert Spotlight: Joe Anderson (DatabaseMX)

We’ve posted a new Expert Spotlight!  Joe Anderson (DatabaseMX) has been on Experts Exchange since 2006. Learn more about this database architect, guitar aficionado, and Microsoft MVP.

Did you put this at the begining of your program ?

_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );

or tried

 _CrtDumpMemoryLeaks();

 in your destructor or ExitInstance
Did you put this at the begining of your program ?

_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );

or tried

 _CrtDumpMemoryLeaks();

 in your destructor or ExitInstance

Author

Commented:
I was doing the opposite: I put _CtrSetDbgFlag at the end of my programm...
Thanks!
Oliver

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial