Profiling memory leaks in Linux
You can use the same valgrind tool:
valgrind --tool=memcheck ./binary
memcheck is a memory error detector. It can detect the following problems that are common in C and C++ programs:
- Accessing memory you shouldn't, e.g. overrunning and underrunning heap blocks, overrunning the top of the stack, and accessing memory after it has been freed
- Using undefined values, i.e. values that have not been initialised, or that have been derived from other undefined values
- Incorrect freeing of heap memory, such as double-freeing heap blocks, or mismatched use of malloc/new/new[] versus free/delete/delete[]
- Overlapping src and dst pointers in memcpy and related functions
- Passing a fishy (presumably negative) value to the size parameter of a memory allocation function
- Memory leaks
On a modern machine, an L1 miss will typically cost around 10 cycles, and an L2 miss can cost as much as 200 cycles. Detailed cache profiling can be very useful for improving the performance of your program.