While trying to track down an annoying memory leak with Visual C++’s debugger, I ran into an issue under which the _CRTDBG_MAP_ALLOC preprocessor flag will make it appear as though the leaky allocations all take place in crtdbg.h (where overloaded, locale-recording versions of the new operator reside).
The fix outlined in this article almost worked (using allocation breakpoints didn’t work at all), but my compiler had a hissy fit about the redefinition of the “new” operator in the supplied function. Perhaps I could have tracked that down, but my inherent laziness prompted me to a different route — collapsing the function and the #define into one. This worked fine and got me the actual location, in my program code, of the offending chunk of dynamic memory:
#ifdef _DEBUG
#define new new(1, __FILE__,__LINE__)
#endif
Don’t know whether my problems with the previous fixes stemmed from compiler settings, project differences, or versioning differences, but the above may be handy for anyone else who needs to track down a leak in VC++ 2005 Express.