Memory Leak detection

A

Archana

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.
 
I

Ian Collins

Archana said:
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
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,955
Messages
2,570,117
Members
46,705
Latest member
v_darius

Latest Threads

Top