Memory Leak detection

Discussion in 'C++' started by Archana, Feb 4, 2008.

  1. Archana

    Archana Guest

    Hi all,

    I am new to c++. I have written one c++ application. I want to detect
    memory leaks from my program.

    I tried with following code which i got from net.
    if(_CrtDumpMemoryLeaks() == TRUE) // reports no leak

    {
    printf("detected 1");
    }
    int *foo = new int[4];

    if(_CrtDumpMemoryLeaks() == TRUE)//reports a memory leak

    {
    printf("detected 2");
    }
    delete[] foo;
    foo = NULL;
    if(_CrtDumpMemoryLeaks() == TRUE)// reports no leak

    {
    printf("detected 3");
    }



    Ideally first time i should not get any memory leak. But when i run
    above code all print statements are executed.

    Can anyone tell me why this is happening?

    Please correct me if i am wrong.

    thanks in advance.
     
    Archana, Feb 4, 2008
    #1
    1. Advertising

  2. Archana

    Ian Collins Guest

    Archana wrote:
    > Hi all,
    >
    > I am new to c++. I have written one c++ application. I want to detect
    > memory leaks from my program.
    >
    > I tried with following code which i got from net.
    > if(_CrtDumpMemoryLeaks() == TRUE) // reports no leak
    >

    <snip>
    >
    >
    > Ideally first time i should not get any memory leak. But when i run
    > above code all print statements are executed.
    >
    > Can anyone tell me why this is happening?
    >

    Who knows? We don't know what _CrtDumpMemoryLeaks() does. If it is a
    platform specific utility, ask on a group for that platform

    --
    Ian Collins.
     
    Ian Collins, Feb 4, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. __jakal__

    c++ memory leak detection

    __jakal__, Apr 28, 2004, in forum: C++
    Replies:
    9
    Views:
    5,110
    StarDrago
    May 24, 2012
  2. Spur
    Replies:
    1
    Views:
    414
    Howard Hinnant
    May 9, 2004
  3. Winbatch

    Memory Leak Detection

    Winbatch, Feb 23, 2005, in forum: C++
    Replies:
    11
    Views:
    8,318
    NitinTheEmbeddedFreak
    Apr 15, 2009
  4. mosaic

    About memory leak detection.

    mosaic, Jul 15, 2004, in forum: C Programming
    Replies:
    7
    Views:
    385
    Bernhard
    Jul 16, 2004
  5. Replies:
    8
    Views:
    1,049
    Ian Collins
    Nov 3, 2006
Loading...

Share This Page