title: C++ - Memory leak testing with _CrtDumpMemoryLeaks() - Does not output line numbers
body: <p>I'm working on a game with SDL in Visual Studio 2010. I came across the <code>_CrtDumpMemoryLeaks()</code> macro and thought I'd give it a go. Invoking <code>_CrtDumpMemoryLeaks()</code> does print memory leaks to the output window, but it does not show where it happens.</p>
  
  <p>I've read the MSDN article at <a href="http://msdn.microsoft.com/en-us/library/e5ewb1h3(v=VS.80).aspx" rel="nofollow noreferrer">Memory Leak Detection Enabling </a>, and it explains that if I define <code>_CRTDBG_MAP_ALLOC</code> it should output the line number of the offending statement. This does not happen in my case. (I was however able to get it to work if I use malloc() directly -- not by using 'new').</p>
  
  <p>The code:</p>
  
  <pre><code>#define _CRTDBG_MAP_ALLOC
  #include &lt;crtdbg.h>
  #include &lt;stdlib.h>
  
  int main(int argc, char *argv[]) {
      int *var = new int(5);
  
      _CrtDumpMemoryLeaks();
  
      return 0;
  }
  </code></pre>
  
  <p>The output is the following:
  <code><pre>
  Detected memory leaks!
  Dumping objects ->
  {58} normal block at 0x007D1510, 4 bytes long.
   Data: &lt;    > 05 00 00 00 
  Object dump complete.
  </code></pre></p>
  
  <p>If <code>_CrtDumpMemoryLeaks()</code> is unable to output line numbers when allocating using 'new' then suggestions for other ways to achieve similar behavior is appreciated.</p>