C++ Memory Leaks: Detection, Integration, and Prevention
You are building or maintaining a C++ service/library and need a practical approach to find and prevent memory leaks across platforms.
Discuss:
-
Dynamic analysis tools and options
-
Linux: Valgrind/Memcheck; AddressSanitizer (ASan) and LeakSanitizer (LSan)
-
Windows: Visual Studio AddressSanitizer, CRT debug heap, Diagnostic Tools
-
macOS/iOS: Xcode Instruments (Leaks/Allocations), command-line leaks
-
Runtime/reporting integration
-
How to run these tools in local dev, test, and CI
-
How to fail builds/tests on leaks
-
Using suppressions and mid-run leak checks
-
Preventive techniques
-
RAII
-
Smart pointers (unique_ptr/shared_ptr/weak_ptr)
-
Ownership rules and coding practices