views:

222

answers:

1

One of my projects is making use of Microsoft's supplied memory leak checker via _CrtSetDbgFlag etc. This is working fine except that I now want to make use of a third-party package which is leaking a small amount of memory. I have no particular need to fix the leaks, but the output is annoying since it will disguise "genuine" leaks that may be introduced.

How does one go about disabling this leak checking for a particular file or project, but leave it on for others? My understanding is that it gets enabled via some #define in debug mode - I've had a bit of a fiddle but haven't managed to find something which I can #undef to switch it off.

+2  A: 

You can deactive the heap allocation checker in the concerned files by use of _CrtSetDbgFlag() and the macro _CRTDBG_CHECK_DEFAULT_DF (which is equal to 0) before the first new instruction in a file where you don't want to check memory leaks and reactive it just after the new instructions. See MSDN here.

Another way only for MFC projects: I personally use the DEBUG_NEW macro to detect memory leaks. In each file of my project I have added the macro. If you don't put the macro in a file, memory leaks will not be found in it but only in the others. The macro is explained here.

Patrice Bernassola
Thanks - flipping the flag on and off works great. I'd gotten too hung up on that having been set and trying to evade the changes to new. It's not a MFC project so the DEBUG_NEW thing doesn't apply in this case, but nice to know anyway :)
Peter
You're welcome Peter
Patrice Bernassola