Massif is a great tool that displays how much memory your program uses over time. It has some drawbacks, though:
- All Valgrind tools are slow; if your program is slow, Massif will slow it down further (by a factor of ten, i think).
- You have to restart your program to use it, you can't intercept it with Valgrind (and Massif) if your program is already running.
- You have to compile your program with the '-g' flag if you want the Massif report to show where in the code memory is used.
If you run Massif with your program, you can run
ms_print massif.out.1234 > output
You don't essentially need the 'output'-part, but I find it easier to interpret the results with less (or some other text file reader) than just scrolling through the terminal history. At the top of output, you will see a graph of your memory consumption over time. Below that, you will see some snapshots from arbitrary time intervals from where you can locate the places in code which took most memory.
There are some graphical tools to interpret Massif results, but I have never felt that I require them. Study the report from ms_print and you will learn to interpret its results.
Good luck!