valgrind
Memory debugging and profiling framework
TLDR
SYNOPSIS
valgrind [--tool=toolname] [options] program [args]
DESCRIPTION
valgrind is an instrumentation framework for dynamic analysis tools. The default tool, memcheck, detects memory management problems: leaks, use of uninitialized memory, buffer overflows, and invalid frees.Programs run significantly slower under Valgrind (10-50x) as every memory access is instrumented. This is normal and expected.Output indicates error type, location (with line numbers if compiled with -g), and call stack. "Definitely lost" memory is a real leak; "still reachable" may be acceptable cleanup deferred to exit.Other tools profile performance (cachegrind, callgrind), detect threading issues (helgrind, drd), or analyze heap usage (massif).
PARAMETERS
--tool=name
Select tool (memcheck, cachegrind, callgrind, helgrind, drd, massif)--leak-check=level
Check for memory leaks (no, summary, full)--show-leak-kinds=kinds
Which leaks to show (definite, indirect, possible, reachable, all)--track-origins=yes|no
Track origins of uninitialized values--log-file=file
Write output to file--xml=yes
Output in XML format--gen-suppressions=level
Generate suppression entries (no, yes, all)--suppressions=file
Use suppressions from file-v, --verbose
More verbose output-q, --quiet
Less verbose output--num-callers=N
Maximum stack depth for error reports (default: 12)--vgdb=yes|no|full
Enable gdb server for debugging under Valgrind
TOOLS
memcheck: Memory error detector (default)cachegrind: Cache and branch profilercallgrind: Call-graph profilerhelgrind: Thread error detectordrd: Thread error detector (different algorithm)massif: Heap profiler
CAVEATS
Compile programs with -g for line numbers and -O0 or -O1 for accurate debugging (high optimization confuses source mapping).False positives occur, especially with system libraries. Use suppression files to ignore known issues.Valgrind doesn't work well with JIT compilers or custom memory allocators without additional configuration.
HISTORY
Valgrind was created by Julian Seward and first released in 2002. The name comes from the entrance to Valhalla in Norse mythology. It has become the standard memory debugging tool for C/C++ on Linux.
