Click here to Skip to main content
16,020,669 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Could you please suggest me one memory leak free tool for c++.

Objective : Free tool should able to identify all memory leaks, that are caused due to memory allocation operators, threads, sockets, files, events etc..
Environment : C++ compiler on Microsoft VisualStudio 2005 on Windows7.


Regards
Narayana Reddy.L
Posted

Instead of getting a leak detector how about not leaking memory in the first place?

This is 2012 and since 2003 (2006 in the case of VC++ - the service pack for VC++2005) C++ has had all the tools you need to NEVER leak resources of any kind, let alone memory. If you leak anything it means you're doing something dodgy and your time would be better spend going back and rewriting your code. Don't try and plug the holes, avoid the iceberg instead.

It's pretty easy to avoid - everywhere you see a pointer or built in array [1] replace them with either a local variable, std::unique_ptr, std::shared_ptr or std::vector. Do that and you'll reduce the number of problems you have between 75% to 99% depending on your application area.

[1] With some exceptions, const arrays are pretty harmless from a resource management point of view.
 
Share this answer
 
Comments
Aescleal 10-Jul-12 10:24am    
Hello Mr. Univoter. Here's my standard question to the likes of you. Can you please tell me why you down voted me so I can either:

- Remove any technical inaccuracies in my answer (I like learning where I get things wrong, it improves my C++ practice)

- Improve the presentation of my answer if it's not clear

- Leave my answer unchanged along with your comment so other people can make up their own minds about whether your criticism and my answer are relevant/timely/appropriate.

Thanks!

PS: I don't do tit-for-tat uni-voting so please don't worry about your rep if you stick your head above the parapet, I really want to know.
armagedescu 11-Jul-12 17:37pm    
Ok, it was me.
In fact, memory leak detection is not a trivial task. It is already in the application, and you have to find it. If a big program leaks, then it impossible to diagnose it just by analyzing the code. Moreover, sometimes is even impossible to know if what we face is a memory leak, or just memory consumption problems. Sometimes you even do not have the sources, but you have to detect the memory leaks with full callstacks, then assign them to development teams to fix. In development environment usually memory usage is much smaller than in real life. In most cases you will not be able to deploy all the development environment to debug at user site.

Speaking in terms of inaccuracies, it is about memory leak detection, not about memory leak avoiding or about best programming practices.
Aescleal 12-Jul-12 5:14am    
Hi, thanks for the reply, it was much appreciated.

My reasoning for my answer was there's often too much emphasis on using tools after a problem's arisen rather than stopping it happen in the first place.

Your point that if you're using a third party library without source or which you can't otherwise modify then tools are the only way to go was really well made and something I completely missed.

Again, thanks for being the first person to reply to one of my messages asking for clarification - with feedback like this it's worth getting 1s once in a while!
You may use WinDbg or DebugDiag. Both tools are free, you can download and install them from microsoft web site. Also some tools like LeakDiag are available, but WinDbg and DebugDiag are much better.
 
Share this answer
 
v2
I would advise you to look not for "memory leak detector", but for "memory debugger".

Wikipedia provides a good list of references, some of those tools are open-source. Please see:
http://en.wikipedia.org/wiki/Memory_debugger[^],
http://en.wikipedia.org/wiki/Memory_debugger#List_of_memory_debugging_tools[^].

Good luck,
—SA
 
Share this answer
 
Have a look at these articles, right from CodeProject. They will most certainly provide what you need:
http://www.codeproject.com/search.aspx?q=memory+leak+c%2b%2b&doctypeid=1%3b2%3b3[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 2-Jul-12 2:39am    
Fair enough, my 5, but my advice is to look for "memory debuggers" instead.
There is a good list -- please see my answer.
--SA

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