share
Stack OverflowIs there a good Valgrind substitute for Windows?
[+210] [38] Drake
[2009-01-05 15:37:39]
[ c windows debugging memory-leaks valgrind ]
[ https://stackoverflow.com/questions/413477/is-there-a-good-valgrind-substitute-for-windows ]

I was looking into Valgrind to help improve my C coding/debugging when I discovered it is only for Linux - I have no other need or interest in moving my OS to Linux so I was wondering if there is a equally good program for Windows.

What kinds of debugging are you looking to do? Valgrind is quite a rich toolset, and the answers below point in all kinds of directions. With an emphasis on memory leak/allocation debugging. - jakobengblom2
(1) Maybe you can test the code on a virtual Linux machine inside your Windows, just when you need to check it. you can share the development folder between the virtual and non-virtual machine. that is, if the code is portable enough. - Liran Orevi
[+117] [2011-07-05 09:13:11] Lailin Chen

As jakobengblom2 pointed out, valgrind has a suit of tools. Depending which one you are talking about there are different windows counter parts. I will only mention OSS or free tools here.

1. MemCheck:

Dr. Memory. It is a relatively new tool, works very well on Windows 7. My favorite feature is that it groups the same leaks' allocation stacks in the report.

http://code.google.com/p/drmemory/

I have also used UMDH( http://support.microsoft.com/kb/268343 ) and found it quiet useful and easy to setup. It works from Win2000 to Win7.

AppVerifier is a must have swissknife for windows native code developers, its "memory" checker does similar job http://msdn.microsoft.com/en-us/library/dd371695%28v=vs.85%29.aspx

2. Callgrind:

My favorite is verysleepy ( http://www.codersnotes.com/sleepy ) It is tiny but very useful and easy to use.

If you need more features, AMD CodeAnalystâ„¢ Performance Analyzer is free: http://developer.amd.com/documentation/videos/pages/introductiontoamdcodeanalystperformanceanalyzer.aspx

Windows Performance Analysis tools is free from Microsoft, not very easy to use but can get the job done if you are willing to spend the time. http://blogs.microsoft.co.il/blogs/sasha/archive/2008/03/15/xperf-windows-performance-toolkit.aspx Download: http://msdn.microsoft.com/en-us/performance/cc752957

3. Massif:

Similar(not quite exact match) free tools on windows are:

VMMap from sysinternals : http://technet.microsoft.com/en-us/sysinternals/dd535533

!heap command in windbg : http://hacksoflife.blogspot.com/2009/06/heap-debugging-memoryresource-leak-with.html

4. Cachegrind:

Above mentioned Windows Performance Tools has certain level of L2 cache miss profiling capability but not quite as good and easy to use as Cachegrind.

5. DRD:

Haven't found anything free and as powerful on Windows yet, the only free tool for windows I can find that is slightly close is the "lock" checker in AppVerifier: http://msdn.microsoft.com/en-us/library/dd371695%28v=vs.85%29.aspx


(2) There's also gperftools (formerly Google PerfTools). It's not a valgrind replacement (what is really) but it has a new malloc, cpu profiler, heap profiler and checker. Worth a look as it's support on Linux and Windows (inc Mingw) and other unices. - alexr
1
[+31] [2010-01-31 19:41:39] Dan Kegel

Why not use Valgrind + Wine to debug your Windows app? See http://wiki.winehq.org/Wine_and_Valgrind

(Chromium uses this to check the Windows version for memory errors; see build.chromium.org and look at the experimental or memory waterfalls, and search for wine.)

There's also Dr. Memory, see dynamorio.org/drmemory.html


(3) Because then you wouldn't be debugging a Windows app - you'd be debugging a Linux app. - John Dibling
(33) No need to recompile in Wine. Just transfer your .exe and .pdb over to a Linux box. And you wouldn't be debugging a Linux app; you're debugging your exact Windows app. - Dan Kegel
2
[+29] [2009-01-05 17:19:23] orip [ACCEPTED]

Some more good commercial tools:

[1] http://www-01.ibm.com/software/awdtools/purify/
[2] http://www.parasoft.com/jsp/products/home.jsp?product=Insure

(1) Purify: venerable but still useful, as shown by how many changes of corporate ownership it has survived! - Norman Ramsey
(2) Insure++ takes forever to instrument your code, and forever to execute your code at runtime. - C.J.
3
[+15] [2009-08-30 13:16:23] tgs_stdio

For Visual C++, try Visual Leak Detector. When I used it, it detected a memory leak from a new call and returned the actual line in source code of the leak. The latest release can be found at http://vld.codeplex.com/.


It does not seem to work for me. I even tried creating a simple project that did basically nothing other than to allocated some memory and not free it. VLD did not detect it. :-| - Synetech
@Synetech inc. I had the same problem in VS2010... Using the newest version of VLD solved my problem - relaxxx
4
[+14] [2009-01-05 16:40:50] dmityugov

Development environment for Windows you are using may contain its own tools. Visual Studio, for example, lets you detect and isolate memory leaks [1] in your programs

[1] http://msdn.microsoft.com/en-us/library/x98tx3cf%28VS.80%29.aspx

(6) It is of very little practical use. It will log the filename/linenumber for offending allocations, but it's only informative if you call malloc directly. When using new/delete, it will unhelpfully pinpoint new.h as the "offending" code. - user9665
(3) It works correctly for me, pointing the right line even new/delete are used. - Rodrigo
But will it work if a library function allocates? E.g. strdup. - Alex Budovski
The Debug CRT, which is what you are trying to describe is useful for C code. Getting it to work for C++ code is more problematic. - C.J.
(1) Valdrind does a lot more then find memory leaks, I mainly use it to find use of freed and uninitialized stack and heap memory which can be incredibly hard to debug otherwise. - ideasman42
(1) @user9665 Visual Leak Detector (vld.codeplex.com) provide full callstack for each memory leak with minimal souce code changes. Check example on site - KindDragon
5
[+14] [2009-10-01 13:59:54] Satbir

i would like to list some tool , hope will be useful

read this article [1] for more detail

  1. Purify
  2. Bounds Checker
  3. Coverity (basically its a code analyzer but, it will catch memory leak in static )
  4. Glow Code
  5. dmalloc
  6. ccmalloc
  7. NJAMD
  8. YAMD
  9. Valgrind
  10. mpatrol
  11. Insure++
[1] http://www.linuxjournal.com/article/6556

6
[+13] [2009-08-28 01:16:54] Diaa Sami

Try DUMA [1]

[1] http://duma.sourceforge.net/

7
[+12] [2009-04-09 05:37:22] user88930

There is Pageheap.exe part of the debugging tools for Windows. It's free and is basically a custom memory allocator/deallocator.

See http://support.microsoft.com/kb/286470


Pageheap/gflags have helped me get to the bottom of some nasty heap corruption problems. - the_mandrill
I found gflags + gdb (from mingw) helpful in diagnosis. - Jarekczek
8
[+8] [2009-10-01 09:45:17] Jasper Bekkers

In combination with Visual Studio I generally use Visual Leak Detector [1] or simply _CrtDumpMemoryLeaks() which is a win32 api call. Both are nothing fancy but they get the job done.

[1] http://vld.codeplex.com

9
[+6] [2009-01-05 15:50:44] Manuel

I had the chance to use Compuware DevPartner Studio [1] in the past and that was really good, but it's quite expensive. A cheaper solution could be GlowCode [2], i just worked with a 5.x version and, despite some problems in attaching to a process i needed to debug, it worked quite well.

[1] http://www.compuware.com/products/devpartner/studio.htm
[2] http://www.glowcode.com/summary.htm

Expensive yes. It paid back in one weekend, just using the profiler piece. - EvilTeach
10
[+6] [2009-01-05 15:58:22] stevex

I've been loving Memory Validator [1], from a company called Software Verification.

[1] http://www.softwareverify.com/cpp/memory/index.html

11
[+5] [2009-10-01 09:16:32] fmuecke

Viusual Studio can help detecting memory leaks itself. See Microsoft Visual C++ Tips and Tricks [1] -> "Memory Leaks" section. See also this post in SO [2]

Although real tracing is only possible with the Team Edtion of Visual Studio.

[1] http://www.highprogrammer.com/alan/windev/visualstudio.html
[2] https://stackoverflow.com/questions/413477/is-there-a-good-valgrind-substitute-for-windows/413709#413709

12
[+4] [2009-01-05 15:53:58] Patrick Cuff

See the " Source Test Tools [1]" link on the Software QA Testing and Test Tool Resources page for a list of similar tools.

I've used BoundsChecker,DevPartner Studio and Intel V-Tune in the past for profiling. I liked V-Tune the best; you could emulate various Intel chipsets and it would give you hints on how to optimize for that platform.

[1] http://www.aptest.com/resources.html#app-source

13
[+3] [2009-10-01 09:04:56] grigy

How about the Purify [1]?

[1] http://www-01.ibm.com/software/awdtools/purify/win/

Not really free... but I guess you could find a test license for testing purposes. - David Rodríguez - dribeas
Dead link as of 2011-02-04 for BoundsChecker. - dwj
14
[+3] [2010-03-03 09:42:00] Agnel Kurian

Does Jochen Kalmbach's Memory Leak Detector [1] qualify?

PS: The URL to the latest version is buried somewhere in the article's comment thread.

[1] http://www.codeproject.com/KB/applications/leakfinder.aspx

15
[+3] [2010-04-19 11:38:00] Alex Budovski

LeakDiag, UMDH, App Verifier, DebugDiag, are all useful tools to improve robustness of code and find memory leaks.


16
[+3] [2010-07-02 07:08:59] zr.

The Boost Test library can detect memory leaks.


17
[+3] [2012-02-21 19:57:46] Alexey Alexandrov

Try Intel's Inspector XE product which can help you detect both memory and threading issues: http://software.intel.com/en-us/articles/intel-inspector-xe/


18
[+2] [2009-01-05 15:56:00] Alex Fort

Perhaps CodeSnitch would be something you're after? http://www.entrek.com/codesnitch.html


19
[+2] [2009-07-15 22:04:30] Vince

If you are developing with Borland/CodeGear/Embarcadero C++ Builder, you could use CodeGuard.


20
[+2] [2009-10-01 09:32:17] RED SOFT ADAIR

More or less all Profilers include checking for memory leaks and show you the stack when the memory was allocated.

I can recommend Intels Parallel Inspector [1]. Simple to use and no recompilation needed. The trial version runs for 30 days.

GlowCode [2] and AtromatedQA [3] also include such capabilites. They all offer free trials.

Compuware DevPartner (aka BoundsChecker) in Contrast needs a slowed down "instrumentation" recompile and the application also runs slower when checking for errors. And BoundsChecker can not work with 64 Bit evsrions at all. We gave up on that tool.

[1] http://software.intel.com/en-us/intel-parallel-inspector/
[2] http://www.glowcode.com/
[3] http://www.automatedqa.com

(2) I'd defintitely recommend glowcode. I've used it in the past to find an memory leak within a dll being called by my app. - Bob
There were complaints of major slowdowns while using DevPartner at my last workplace. They do everything to avoid using it because of how slow it would be. - Calyth
21
[+2] [2009-10-01 10:23:01] Dror Helper

The best tool I ever used is DevPartner BoundsChecker [1] - it's not free but it has an evaluation period.

[1] http://microfocus.com/products/DevPartner/BoundsCheckerSuite.asp

22
[+2] [2010-04-02 13:57:19] Stephen Kellett

Another memory tool for your list: Memory Validator [1].

Not free, but nowhere near as expensive as Purify or Boundschecker.

[1] http://www.softwareverify.com/cpp/memory/index.html

23
[+2] [2010-08-09 14:15:51] rogerdpack

If you're not afraid of mingw, here are some links (some might work with MSVC)... http://betterlogic.com/roger/?p=1140


24
[+2] [2011-04-06 10:56:02] Ira Baxter

We are just completing a Memory Safety checking tool [1] for Windows, that handles GCC and Micrsoft Visual C (not C++ yet), and are looking for Beta testers.

EDIT June 12, 2011: Not Beta anymore, now production for GCC and Microsoft Visual Studio C.

[1] http://www.semanticdesigns.com/Products/MemorySafety

25
[+2] [2012-06-05 09:17:48] Calmarius

I found this SF project today:

http://sourceforge.net/p/valgrind4win/wiki/Home/

They are porting valgrind to Windows. Probably in several years we will have a reliable valgrind on windows.


26
[+1] [2009-10-01 09:07:03] maykeye

Check out this question: Is there a good Valgrind substitute for Windows? [1] . Though general substitute for valgrind is asked, it mainly discusses memory leak detectors and not race conditions detections.

[1] https://stackoverflow.com/questions/413477/is-there-a-good-valgrind-substitute-for-windows

27
[+1] [2009-10-01 09:11:09] Rob Wells

Definitely Purify! I've used that to analyze some massive code bases (>3,000 kSLOC) and found it to be excellent.

You might like to look at this list [1] at Wikipedia.

By the way, I've found memwatch [2] to be useful. Thanks Johan!

[1] http://en.wikipedia.org/wiki/Memory_debugger
[2] http://www.linkdata.se/sourcecode.html

28
[+1] [2009-10-01 09:42:05] Red

I used Insure++ which does excellent job in finding c++ memory leaks/corruptions and many other bugs like uninitialized variables, pointer errors, strings etc., It also does visual "Code coverage" and run time memory usage etc.. which give more confident on your code.. You can try it for trail version..


29
[+1] [2009-10-01 11:41:28] Cristian Adam

You might want to read what Mozilla is doing [1] regarding memory leaks. One tool in their toolbox is the Hans Boehm garbage collector used as memory leak detector. [2]

[1] https://developer.mozilla.org/En/Debugging_memory_leaks
[2] http://www.hpl.hp.com/personal/Hans_Boehm/gc/leak.html

30
[+1] [2009-10-01 12:15:56] Patrice Bernassola

You can give a try to RuntimeChecker [1] trial ot to IBM Purify [2] trial..

A free solution would be to use the following code in Visual Studio:

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

Just write this in the top of all your cpp files. This will detect memory leaks of your application whenc stopping debug run and list them in the output window. Double clicking on a memory leaks line will higlight you the line where memory is allocated and never released. This may help you : http://www.flipcode.com/archives/How_To_Find_Memory_Leaks.shtml

[1] http://www.runtimechecker.com/
[2] http://www-01.ibm.com/software/awdtools/purify/

31
[+1] [2009-10-01 18:20:57] Kirill V. Lyadvinsky

The user-mode dump heap (UMDH) utility [1] works with the operating system to analyze Windows heap allocations for a specific process. That's a pretty good tool for free from Microsoft. Here [2] is a mini tutorial "How to use Umdh.exe to find memory leaks".

[1] http://msdn.microsoft.com/en-us/library/cc267868.aspx
[2] http://support.microsoft.com/kb/268343

32
[+1] [2010-03-15 10:36:48] Ashley Davis

The free tool DebugDiag will help find memory and handle leaks.

You don't need to augument your program for DebugDiag to work.

http://www.microsoft.com/downloads/details.aspx?FamilyID=28BD5941-C458-46F1-B24D-F60151D875A3&displaylang=en [1]

Although it is not the easiest or most intuitive program to use! Make sure you google for tutorials and instructions on how to use it.

[1] http://www.microsoft.com/downloads/details.aspx?FamilyID=28BD5941-C458-46F1-B24D-F60151D875A3&displaylang=en

33
[+1] [2011-07-21 03:33:00] Ricky Lung

You can take a look to the article Design and Implementation of an In-Game Memory Profiler [1] in the book "Game Programming Gems 8".

It shows how to implement a low overhead semi-intrusive real-time memory profiler, source code provided in the CD-ROM.

enter image description here

[1] http://my.safaribooksonline.com/9781584507024/ch37

34
[+1] [2012-09-24 00:32:15] thegreendroid

Clang supports the Address Sanitizer plugin (-faddress-sanitizer option), which can pretty much detect most bugs that Valgrind can find (does not support detection of uninitialised memory reads and memory leaks yet though). See this page [1] for a comparison against Valgrind and other similar tools. An official Windows port is currently in progress, see Windows ASan port [2].

I attempted to build it myself on Windows a couple of months ago and gave up, see my related question [3]. Things may have changed for the better now if you want to give it another go.

[1] http://code.google.com/p/address-sanitizer/wiki/ComparisonOfMemoryTools
[2] http://code.google.com/p/address-sanitizer/wiki/WindowsPort
[3] https://stackoverflow.com/questions/11806469/clang-with-faddress-sanitizer-on-windows

35
[0] [2011-02-06 16:58:12] adrian

Just an idea, you could also implement a memory allocator and track all calls to malloc and free. However this might be too much for some projects.


That's how most games do it. But it's a huge undertaking and a lot of instrumentation. - Crashworks
36
[0] [2011-04-05 20:31:38] Wayne Ariola

Parasoft Insure++ has always been reliable:

http://www.parasoft.com/jsp/products/insure.jsp?itemId=63


37
[0] [2012-08-09 11:25:29] Avinash

Finding Memory leak in C++ Application on Windows [1]

[1] http://avdongre.wordpress.com/2012/08/09/finding-memory-leak-in-c-application-on-windows/

38