Valgrind's massif tool is an easy way to see what lines of code are responsible for the most memory allocations. To run massif, simply
- Run the program under question under massif with valgrind --tool=massif my_program my_program_args
- When the program exits (it will run much more slowly than usual), it will emit a file to the current directory called massif.xxxx where xxxx is the pid of the instrumented program
- ms_print massif.xxx will print out a textual description of the memory allocations made in the program
- If your system has KDE support, massif-visualizer may also show this info as a graphical program.