locked
Memory leak detection in C++ RRS feed

  • Question

  • One of my application works fine in debug but fails in release mode.My guess was it is due to memory leak issue so I google & included following code lines in the code.

    #define _CRTDBG_MAP_ALLOC
    #include <stdlib.h>
    #include <crtdbg.h>

     

     

    &

    _CrtDumpMemoryLeaks();

    It has returned some results of memory leak detection but not having any locatin of memory leak.How could I find that?

    here is o/p of it-

    Detected memory leaks!

    Dumping objects ->

    {976} normal block at 0x29700240, 152 bytes long.

    Data: <ÍÍÍÍ p) Š > CD CD CD CD 80 0F 70 29 00 00 00 00 8A 00 00 00

    {974} normal block at 0x29700310, 152 bytes long.

    Data: <ÍÍÍÍ p) Š > CD CD CD CD 80 0F 70 29 00 00 00 00 8A 00 00 00

    Object dump complete.

    Tuesday, July 13, 2010 7:00 AM

Answers

  • >It has returned some results of memory leak detection but
    >not having any locatin of memory leak.How could I find that?

    See:

    Finding Memory Leaks Using the CRT Library
    http://msdn.microsoft.com/en-us/library/x98tx3cf.aspx

    Excerpt:
    --------------------------------------------------------------
    These techniques work for memory allocated using the standard
    CRT malloc function. If your program allocates memory using
    the C++ new operator, however, you need to redefine new if you
    want to see the file and line numbers in the memory-leak report.
    You can do that with a block of code that looks like this:

    #ifdef _DEBUG
       #ifndef DBG_NEW
          #define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )
          #define new DBG_NEW
       #endif
    #endif  // _DEBUG
    --------------------------------------------------------------

    - Wayne
    Tuesday, July 13, 2010 10:22 AM

All replies

  • >It has returned some results of memory leak detection but
    >not having any locatin of memory leak.How could I find that?

    See:

    Finding Memory Leaks Using the CRT Library
    http://msdn.microsoft.com/en-us/library/x98tx3cf.aspx

    Excerpt:
    --------------------------------------------------------------
    These techniques work for memory allocated using the standard
    CRT malloc function. If your program allocates memory using
    the C++ new operator, however, you need to redefine new if you
    want to see the file and line numbers in the memory-leak report.
    You can do that with a block of code that looks like this:

    #ifdef _DEBUG
       #ifndef DBG_NEW
          #define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )
          #define new DBG_NEW
       #endif
    #endif  // _DEBUG
    --------------------------------------------------------------

    - Wayne
    Tuesday, July 13, 2010 10:22 AM
  • You can use the following free library which has more features than the DBG_NEW solution:

    http://vld.codeplex.com/

    X.

     

    Tuesday, July 13, 2010 7:04 PM