views:

847

answers:

5

Anyone know of a profiler and leak detector that will work with VS2010 code? Preferably one that runs on Win7.

I've searched here and in google. I've found one leak detector that works (Memory Validator) but I'm not too impressed. For one thing it shows a bunch of menu leaks and stuff which I'm fairly confident are not real. I also tried GlowCode but it's JUST a profiler and refuses to install on win7.

I used to use AQtime. It had everything I needed, memory/resource leak detection, profiling various things, static analysis, etc. Unfortunately it gives bogus results now.

My main immediate issue is that VS2010 is saying there are leaks in a program that had none in VS2005. I'm almost certain it's false positives but I can't seem to find a good tool to verify this. Memory Validator doesn't show the same ones and the reporting of leaks from VS doesn't seem rational.

+1  A: 

Personally, I'm fond of DevPartner. If you work in a big company, maybe you can convince them to pay for the hefty license. It's expensive, but it's very very sturdy.

Ori Osherov
A: 

I used several commercial alternatives and although they can deliver fantastic results, they also often simply fail to work because of unknown reasons:

  • Rational Quantity: fantastic product for performance profiling, but they failed to release new versions during several years, and often (in my case) the software often refused to work
  • AQTime: also very good (less than Rational Quantity) but also sometimes refuses to work for unknown reasons.
  • Performance validator: same

In the last years I returned to the rather crude way of sampling the application. This is not as perfect as using instrumentation, but it's much faster, can be run on any application and always works. My favorite is "Very Sleepy" (http://www.codersnotes.com/sleepy) but also Luke StackWalker (http://lukestackwalker.sourceforge.net/) is quite good. Because the applications can be run immediately and without a noticeable slowdown, the "change app, profile" loop is very short and efficient.

For finding memory leaks, there are several tools in Windows that you can use. Again, they are far from perfect, and often can only investigate running applications from the outside, not simply reporting leaks at the end of the application. Look for the "Microsoft Debugging Tools" (UMDH, LeakDiag, gflags). Personally, I find it much easier just to write my own memory manager, and let it report the leaks at the end of the application. It's not that hard to write. What you have to do is:

  • Implement the correct new and delete operators (I think you should implement 4 new and 4 delete operators)
  • In the implementation of new, get the call stack (look for StackWalk) and store this with the allocated memory.
  • Make a class that starts your memory manager in the constructor, and report all the leaks (including the call stack) in the destructor.
  • Make a global variable of that class-type. It might be needed to make it a special global variable using a #pragma(init_seg).
Patrick
+2  A: 

For finding memory leaks you can try Visual Leak Detection tool.

Wacek
A: 

There's really simple and easy to use Leak Detection code here too: http://www.codeproject.com/kb/cpp/MemLeakDetect.aspx

DrDeth
A: 

Not sure how to link to this, which I previously posted in response to a similar question:

You can use umdh.exe to capture and compare snapshots of the process before and after leak happens. This works best with Debug binaries but is viable with Release provided symbol paths are correctly set - it will give you the callstacks of memory allocated between the 1st and the 2nd snapshot.

http://support.microsoft.com/kb/268343

This approach has the advantage of being free.

Steve Townsend