Valgrind
Valgrind is a powerful tool that can help us track down memory leaks in our programs. Run in the terminal, Valgrind tracks memory reads and writes in programs, as well as making sure that free()
is appropriately applied to any malloc()
, calloc()
, or realloc()
call. This section will go over the basics of how to use Valgrind. For the rest of the course, students will be expected to use Valgrind to track down memory leaks in their code.
-
Lecture
-
Short
-
Supplementary Resources
- Valgrind.org on The Valgrind Quick Start Guide
- Katrik Anand on Developer toolkit – Using valgrind
-
Thought Questions
- Why is it important to track down memory leaks? (Hint: Think about why it would be bad for memory to be “definitely lost.”)
- How does using Valgrind help us debug our code?
- What are some strategies for breaking down and understanding long, complicated error messages that contain important information?
-
Problems