Click here to Skip to main content
15,889,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hallo dear,
Can you please guide me, how to handle memory leak in side CONSTRUCTOR in a very simplest & best way.

I want to use any free Memory-Leak detector TOOL available online. I'hv searched online but unfortunately i didn't get any good easy Tutorial for the same. So please share this knowledge also soon.

Kindly please help me asps.
Posted
Updated 22-Nov-11 22:34pm
v5
Comments
Sergey Alexandrovich Kryukov 1-Oct-11 23:53pm    
Would you also ask how to "mozart" a leak?.. :-)
--SA
Stefan_Lang 23-Nov-11 4:25am    
If you already know where the leak is, why do you need a tool? That is exactly what a tool will tell you.
Albert Holguin 23-Nov-11 9:03am    
This is what came to my mind when I first saw this...lol

You may want to take a look at this article:
Memory Leak Detection[^]

Be sure to read up on the features provided with Visual C++:
http://msdn.microsoft.com/en-us/library/x98tx3cf.aspx[^]

Best regards
Espen Harlinn
 
Share this answer
 
Comments
litupkj 1-Oct-11 6:47am    
Thanks Harlinn
Hoping your links will be helpful.
If you hav any more links,these are most welcome.
Simon Bang Terkildsen 1-Oct-11 17:54pm    
That's one great article, my 5
Espen Harlinn 2-Oct-11 5:47am    
Thanks Simon!
Sergey Alexandrovich Kryukov 1-Oct-11 23:53pm    
Good advice, my 5.
--SA
Espen Harlinn 2-Oct-11 5:48am    
Thanks Sergey!
How do you know you have a memory leak ?

If you have the class (and the constructor) code then it should be easy to trace the code and pin-point the memory allocations or more importantly, the non-existant memory de-allocation.

If you put the class in a simple project and create an instance of the class on the stack and exit the process normally, does it leak ? (i.e. is the debugger listing memory leak at the end of the debuggin session?)

for example :

C++
class YouClass;

int main(...)
{
  YourClass yourClass;

  return 1;
}


does that leak ?

if you allocate on the heap with new, do you delete the memory with delete ?


C++
class YouClass;

int main(...)
{
  YourClass* yourClass = NULL;
  yourClass = new YourClass;

  delete yourClass;
  yourClass = NULL;
  return 1;
}


If the simple program leaks, check the class and track allocation, and also de-allocation, especially in the destructor.

Max.
 
Share this answer
 
 
Share this answer
 
Comments
Albert Holguin 23-Nov-11 9:05am    
There are a lot of resources in regards to this already here at CP... +5
To clarify is in you event the leak or not, you can use a series of programs. Programs such as valgrind for example. Or, are often advised such plugin as deleaker. The name speaks for itself. Using such detectors can find the line that is leaking and then have to think how to fix it.
 
Share this answer
 
Have a look at http://en.wikipedia.org/wiki/Cppcheck[^]. I'm about to try it myself, although for different purposes.

I've looked for leak detection tools a couple of years ago, but found there were precious few good ones for Windows at the time, and all of them more or less expensive. (I didn't find Cppcheck, maybe it didn't exist yet). If you work on Linux though, check out ValGrind. It's got a good reputation.
 
Share this answer
 
I guess you can use klocwork for static checking

http://www.klocwork.com/solutions/insight-defects/index.php[^]
 
Share this answer
 
Comments
Albert Holguin 23-Nov-11 9:07am    
I'm pretty sure that's a pricey product... met these guys at a tradeshow... product seems too bulky for just doing this (has too many features).
Here is the answer I gave to a similar question.
Memory leakage detection[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900