Visual C++ - Memory Leak Detection - c++

Any suggestions? This SO post talks about Visual Leak Detector, but I'm looking for other tools. Also, please don't recommend this.

I've used Visual Leak Detector quite recently and it works pretty well. It's very simple to build it in (just include vld.h) and doesn't require any instrumentation. I found that I needed to write a couple of scripts though to parse the output into something more useful for my purposes (it is crying out for a decent GUI). Note the new website -- the project is being actively maintained on Codeplex -- the Codeproject link is very old.

Try Deleaker or DevPartner, these both are good enough.
update:
C++ Memory Validator, works fine and fairly priced.

If you can afford some money use the Intel Parallel Inspector (https://www.intel.com/content/www/us/en/developer/tools/oneapi/inspector.html).
It doesn't require any code modifications and provides good reports.
I had to look for good tools to do that in work and that's the best tool (by far) that I found.

As suggested by Noah Roberts, i too felt Memory validator as the best tool for detecting leaks in Visual studio.
Purify also works.

Asked a similar question not long ago but related to 2010 specifically: VS2010 profiler/leak detection
If you're not using 2010 you might consider AQtime. It's not too terrible most the time. There are times thought when it fails to find an object related to the leak and just says "crt memory" or whatever.
Another I recently tried is called "Memory Validator". Not exactly a nice interface but it does seem to work, and work with 2010 too (just doesn't have any other kind of profiling in it, which is something I expect in a commercial tool like that).
Maybe GlowCode as was mentioned in other, similar questions, on SO when I searched before asking.

There is also application verifier. It can track a whole bunch of other issues as well apart from leaks like places where you forget to free win32 objects such as handles etc ...
The MSDN link is: http://msdn.microsoft.com/en-us/library/ms220948(VS.80).aspx

Jacob, the BoundsChecker tool inside DevPartner Studio contains two types of leak detectors for VC++. The uninstrumented version will tabulate leaks at process shutdown. The compile time instrumented detector will break on leaks at the time the leak occurrs showing both the current call stack at the point of leakage, and the allocation stack trace showing where the leaking memory was allocated. The 64-bit version of DPS and BoundsChecker 10.5 ships February 4, 2011 with x64 application support for Visual Studio 2010, 2008, and 2005. We also have a new pricing model so you can license just the BoundsChecker features and ugrade to the full DPS suite only if you find you need the other profilers or static analysis capabilities later on. Be sure to haggle with your sales rep too. Paying list price is like paying sticker price on a new car. Shameless plug: I work on the DevPartner team. DPS 10.5 represents my team's biggest release of tech capability since Compuware closed the NuMega lab. Please evaluate it for your own application and tech stack when 10.5 goes live. Cheers. Matt Schuetze, DevPartner Product Owner (and yes that means PO in normal Scrum team roles.)

VLD cannot be trusted for more serious projects.
Intel has a good tool called Inspector.
After 3 days searching for a good tool to find leaks on x64 binaries with C++ in Visual Studio, this is the only good option I found.

Try Dr.Memory.
They have proper visual studio integration and documentation is excellent.
Easy to use too.

https://sourceforge.net/projects/diagnostic/
http://diagnostic.sourceforge.net/index.html
I had tried so many memory leak detectors that it's difficult to count them all. Some of them crashed, some of them produced invalid results, some of them simply did not help. Eventually I've made my own leak detector, but invested so much effort into it - so made it non-free for time being. Managed / native / 32 & 64-bit architectures supported.
If you ever want to develop this tool further, please feel free to contact me.

Related

Which C++ Profiler to use?

I am supporting a C/Cpp application and have resolved few memory leak issues by creating objects. Since it is provided by the third party API, it is told that the objects gets destructed by the API itself.
I could manage to fix the issue and test my application without any issue. But i still doubt my fix for memory leak. I want to do profiling and i am in need of a Cpp tool that can tell me if there are chances of memory leaks in the code given a CPP file.
Is there a tool of that sort? Any help is greatly appreciated.
Thanks,
~Jegan
You are probably looking for a dynamic analysis tools, not a profile. For Linux, there's valgrind. For windows some good commercial solutions are Purify and Insure++.
Give valgrind a try, it's by far the best memory analysis tool I've come across. It only runs on *nix, but you haven't stated your platform.
We're using MemoryValidator from http://www.softwareverify.com/.
It provides a fully functional 30 day trial, so you can test it before buying.
Single license from 179$ (each for 10 licenses), up to 299$ (1 license). And it is really worth it's price. Enables you to find the cause for leaks within a minute.
Also check the other tools they're providing: performance validator, bug validator and so on.
Great tool once you know how to handle it :-)

C++ BoundsChecker followup

We've been running for years with BoundsChecker for Visual C++ 6 (I think it was BoundsChecker 5 or 6, too). We've upgaded to VS2008 (finally!), and now need a follow-up for the outdated BoundsChecker.
How's the landscape?
What tools are out there?
Any new kids in town?
Any new ideas dealing with the problems we used memory profilers for?
Your recent experiences with these tools?
Recommendations?
The main application is C++ with many COM DLL's, we are looking to track native, C++ and COM leaks and objects. Bounds Checker for that size was already a pain in performance, sorting out the slew of data and some of its limitations.
Support for managed applications (primarily C#) is required, though that may be a separate tool.
Related (but IMO incomplete) question: Modern equivalent of BoundsChecker for Visual Studio 2008
[edit]
Regardign the comment, "In modern C++, you just use self-checking types, and bounds are never broken" :
Reference counted smart pointers can have cyclic references. Interfacing COM components is inherently unsafe, as it requires a lot of manual memory management. I've had a UI-less 3rd party service leak GDI handles so it crashed our overnight tests - the vendor blamed it on a "strange" Microsoft API. I have to interface C-based libraries, I have tons of legacy code that assumes allocation trickery in the sense of Numerical Recipes is a good thing and variable names longer than 3 letters are for typists. I have code from engineers for whom a std::vector<double>::iterator looks much more scary than a double ***, good luck developing and testing these without a solid background in signal processing.
So unless you come here, rewrite and encapsulate the core of a million lines of code in fool-proof C++ classes and make sure a few dozen products still work as before, keep your smart-assery to yourself. I wish I wouldn't need a memory checker, but I do. Thank you.
Disclaimer and warning: I work for Micro Focus, owner of the DevPartner Studio and BoundsChecker products.
BoundsChecker 10.5, part of DevPartner Studio 10.5 (though you can buy it by itself), supports Visual Studio 2005, 2008 and 2010 unmanaged code for 32 and 64 bit applications in essentially the same way it supported 32 bit applications on Visual Studio 6.0. While enhancing it to support X64 applications, we found and fixed quite a few very old problems, and made a start at working in spite of the .NET 4.0 code present in some VS 2010 applications. I say "in spite of" because .NET 4.0 turns out to do a lot of very nasty things in the process space, doing some things that Microsoft warns everybody else not to do, and has a certain amount of built-in resistance to tools like BoundsChecker, which are essentially gigantic viruses.
Anyway, since that release (February 4th), we have updated it to work on Windows 7 SP1 (which isn't quite public yet), and as far as BoundsChecker is concerned, we work with Visual Studio 2010 SP1 as well. We also discovered a nasty .NET 4.0 trap, and figured out to prevent it from taking us down. These enhancements and fixes will be available in our next public update, hopefully within the next month or so.
I have a massive application (here at work), and the new bounds checker 10.5 (supports 64 bit apps now) pretty much works with it. The trick Max is not to turn on all the checker features of devpartner bounds checker at once. Turn on just memory leaks, or turn on just some other feature, then run your app. And by all means exclude modules you don't need. There are quite a few things you can use to tune your settings so it goes faster. But yes, it does take a performance hit. But that is the name of the ballgame.
Intel's Parrallel inspector gave us thousands and thousands of false positives. Didn't use it.
Purify only works on 32 bit apps. i.e. small 32 bit native apps. Forget about using it with a managed C++ app.
And just for the record, if you have a large 32 bit app, memory analysis tools in general won't work very much, because of the massive memory overhead. And since you have very limited memory in a 32 bit address space, you quickly run out of room, and the tools fail.
We evaluated Boundschecker, Intel's Inspector and Purify.
They were all more or less crap.
For our main application, BoundsChecker would not start it after many hours; it only worked for a couple of smaller applications; but find a couple of things (I think we're still in contact with them to figure things out)
Intel's Inspector works, but does not instrument the code, it runs on the executable only (maybe works better when used with the whole suite of Intel products).
Purify failed miserably; we were never able to use it.
We're still in limbo about that.
Max.
Boundschecker: I just bought a (&(^ subscription which only entitles me to use the damned product for 99 days, so I'm pretty damned upset about that) but anyhow I was having big memory troubles and thought I ought to run this thing. It seems to catch lots of interesting things, but is so damned slow that, well put it this way: my appliciation is still in the DLL init code; it has been running for at least a couple hours, and so far it hasn't even gotten as far as the app does normally in the first COUPLE SECONDS. Boundschecker used to be 'the shit' back in numega days, but it seems like it is really another technological orphan being peddled by an opportunitstic business entity, like borland compilers.
So I really like it when it works, it has lots of great info. I just need to see if I will be able to actually get any decent results. It is currently using 4+ GB of RAM and hasn't even started up fully yet. Since I use win7/64 with a crippled home edition which will only recognize 12GB, I may run out of memory before anything really interesting happens. And it will be sometime a few days from now...

C++ dynamic review tools

What's the best tool (commercial/open source) you've used for dynamic review/memory analysis of a C++ application?
EDIT: removed 'static' as there is already a great question on this topic (thanks Iulian!)
For dynamic memory analysis definitely Valgrind.
CPPCheck has served me well for a while now. This is for statical analysis.
Ryan, if you are on Windows and using MSVC++, then I can recommend BoundsChecker within DevPartner VC++ edition from Micro Focus. It has a feature within its memory tracking analysis called the Memory Resource Viewer. You use this to mark a point in time then look for allocations from that point forward. This plus the traditional heap corruption and other memory checks should help you dynamically track your C++ heap and stack issues. Shameless plug: I work on the DevPartner team. Look for DPS 10.5 with 64-bit support in BoundsChecker to launch February 4, 2011 at http://www.DevPartner.com.
Valgrind on Linux
Duma on Windows
For static code review KLOCWORKS is good.
For memory profiling, memory leaks identification, devpartner is a very good one.
Microsoft FxCop for static analysis (free). Parasoft Insure ($$$$) or IBM Purify ($$) for dynamic memory analysis.

Modern equivalent of BoundsChecker for Visual Studio 2008 [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
In VS6 times there was BoundsChecker from Numega. I understand it is dead now, please correct me if I am wrong. What are the reliable alternatives? Preferably free or at least with trial version available.
IMO It might be a better idea to write custom memory manager (the one that supports new/delete/malloc/free wrappers). Make a new/delete wrapper that locks unused/freed memory using VirtualProtect (yeah, I know that default allocation block will have to be PAGE_SIZE bytes large, and you'll need a lot of ram even for a small app, but that's the only disadvantage). If you are on linux, it probably have VirtualProtect alternative. In this case any outrageous out-of-bounds access will generate access violation and will be easy to track. Also use stl containers when possible - they also offer bounds checking.
This advice is based on experience - I had worked with a terribly written huge (several megabytes of code) old software that had memory leaks, accessed already freed memory from multiple threads and so on. I've spent week trying different utilities (purify, devpartner studio, aqtime etc), and although some of them provided loads of information, none were really helpful. With custom memory managment problems were eliminated in 2 days (that includes writing memory manager).
If that doesn't work for you, try compuware devpartner studio - if it is still available anywhere.
BoundsChecker is certainly not dead. "It's only mostly dead, which means partly alive" (sorry, cannot resist the Miracle Max quote from The Princess Bride.) Seriously, BoundsChecker is alive and thriving under Micro Focus stewardship. We are releasing DevPartner Studio with 64-bit application support in BoundsChecker, the .NET/native/mixed performance and coverage profilers, and the .NET memory and holistic CPU/network/disk IO performance profiler. Look for DPS 10.5 to ship on February 4, 2011. The 10.5 release integrates seamlessly with Visual Studio 2005, 2008, and 2010, but you can still use BC standalone to run Active Check against VC6 and VC2003 binaries with some success if needed. Shameless plug: I work on the DevPartner team. I am peppering SO with notes announcing the newfound relevance of DPS 10.5 for C++ and .NET app dev troubleshooting on the x64 platform. With the new pricing model where you can license just BC or just the perf profiler, DPS should be much more accessible than it ever was under Compuware stewardship and lofty pricing. Disclaimer: these are my own opinions not necessarily sanctioned by Micro Focus.
Boundschecker is not dead. I'm using it with Visual Studio 2008.
They just changed owners (Compuware to MicroFocus, to Borland), now it's called DevPartner for Visual C++ BoundsChecker Suite
Check this:
http://www.borland.com/Products/Software-Testing/Automated-Testing/Devpartner-Studio
Bounds Checker used to be my second favorite tool, after a good debugger. I found it incredibly useful. Then it got so freakin expensive that I was no longer able to justify its purchase. If you want to know why hardly anybody even knows about this great tool anymore, there's your answer.
I also work for Micro Focus, and am the main guy right now for the BoundsChecker (DPS Error Detection) runtime internals. The product is definitely not dead, but the main thing keeping it alive right now is the fanatical loyalty of certain people. Though loyalty only goes so far. We continue to have customers. If the product weren't selling at all, the company would have laid us all off long ago and canned the product.
Anyway, for those of you with questions or bugs to report, try our forum at http://community.microfocus.com/.
Purify (Plus)
http://www-01.ibm.com/software/awdtools/purifyplus/
BoundsChecker was acquired multiple times and is now here: http://microfocus.com/products/DevPartner/BoundsCheckerSuite.asp
Another option is Rational Purify (Now owned by IBM): http://www-01.ibm.com/software/awdtools/purify/
Both of these products work, kinda. But neither are a silver bullet and bring with them a non-trivial amount of work to get useful information out of them. YMMV

C++ Code Profiler

Can anybody recommend a good code profiler for C++?
I came across Shiny - any good? http://sourceforge.net/projects/shinyprofiler/
Callgrind for Unix/Linux
DevPartner for Windows
Not C++ specific, but AMD's CodeAnalyst software is free and is feature-packed.
http://developer.amd.com/cpu/codeanalyst/codeanalystwindows/Pages/default.aspx
Gprof if you use gcc. It may not be user friendly but still useful.
Probably you will be interested in Intel VTune. Rather useful and allows to collect low-level events like cache misses which helps a lot in tuning.
Quantify (part of the IBM/Rational PurifyPlus package) is a very good profiler, but not exactly cheap. It is available on several platforms, too - I've used it on Solaris, Windows and Linux.
Depends on what you need to do:
Measure, so you can do regressions testing to see if changes in performance happened.
Find reasons for suboptimal performance and optimize them.
These are not the same.
For 1, use one of the recommended profilers.
For 2, the profiler I much prefer is one you already have:
http://www.wikihow.com/Optimize-Your-Program%27s-Performance
To see how this goes, check this out.
For C++, as for C# and any language that encourages layers of abstraction, those layers may or may not be good from a software engineering standpoint, but they can kill performance. Every method call is a detour in the execution of your program, and the style encourages you to nest those things, sometimes needlessly. Also the style discourages you from knowing or caring what goes on inside them. You may find them creating and deleting objects underneath at a rate and level of generality far beyond what your application really needs.
AQtime (for Windows)
If you are running a Premium version of VS 2010 then you get a profiler with it.
I've also used a couple of other free ones, but they don't compare to the on MS ships. Useful as a second opinion though.
If you have access to a Mac, then I recommend using Shark from the CHUD tools.
You can use the analyzer that´s in Sun Studio 12 on Linux or Solaris. Itś free. http://developers.sun.com/sunstudio/index.jsp
If you cannot locate DevPartner it is because we've moved under new ownership. Check us out on the Micro Focus website: http://www.microfocus.com/products/micro-focus-developer/devpartner/index.aspx. Shameless plug: I work on the DevPartner team. Our long awaited 64-bit versions of BoundsChecker and C++/.NET profilers ship on February 4, 2011. We've changed our pricing model so you can choose either the whole suite or just the performance profiler if that's what you need. Please check out the new DPS 10.5 release when it goes live!