valgrind
Memory debugging and profiling framework
TLDR
Check for memory leaks
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
TOOLS
memcheck: Memory error detector (default)
cachegrind: Cache and branch profiler
callgrind: Call-graph profiler
helgrind: Thread error detector
drd: 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.
