Table of contents
1. What is valgrind?2. How to install valgrind?
2.1 Linux (Ubuntu/Debian)
2.2 macOS
2.3 Fedora/Red Hat (RHEL/CentOS)
2.4 Windows
3. How to use valgrind to detect memory leaks
3.1 Valgrind output examples
3.2 How to write a leak-free code?
3.2.1 Always free allocated memory
3.2.3 Check for memory allocation failures
3.2.4 Avoid memory leaks in loops
3.2.5 Use smart pointers (C++)
Command: ./no_memory_leak
shows the program that valgrind analyzed.