+2  A: 

You might need these defines after your includes


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
ULysses
That's MFC only
humbagumba
No, it works perfectly fine without MFC.
First, this re-defines new which is a bit horrible and breaks any existing placement new uses; secondly it needs a valid definition for `DEBUG_NEW` which is only provided in a standard VC install in `afx.h` which is very much an MFC header.
Charles Bailey
+4  A: 

That's an old version of Visual Leak Detector.

Try this: http://vld.codeplex.com/

Tafsen
Thanks for pointing that out. I delete my answer in favor of yours. Also, you should write your answer more like an actual answer instead of a comment.
Space_C0wb0y
+2  A: 

Check out the piece of code.

Overloading operator new and operator delete to log all memory allocations and deallocations

I identified my memory leaks using this method.

DumbCoder
+2  A: 

When you define _DEBUG and include <crtdbg.h> you get an overloaded operator new which takes additional parameters which you can use to specify the file and line numbers in placement new expressions.

E.g.

int* p = new (_NORMAL_BLOCK, __FILE__, __LINE__) int(5);

You can wrap this in a conditionally defined macro, e.g.

#ifdef _DEBUG
#define DEBUG_NEW_PLACEMENT (_NORMAL_BLOCK, __FILE__, __LINE__)
#else
#define DEBUG_NEW_PLACEMENT
#endif

int* p = new DEBUG_NEW_PLACEMENT int(5);

While you do see people defining a macro new to completely hide this form client code, I do not personally recommend it as it breaks anything already intentionally using placement new and you have to make sure that any headers using placement new (such as many standard headers) are included before any header redefining new. This can make it easy to let some inline uses of new in header files slip through without being 'adjusted'.

Charles Bailey