By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,658 Members | 1,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,658 IT Pros & Developers. It's quick & easy.

Memory Leak detection

P: n/a
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.
Feb 4 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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.
Feb 4 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.