This question is covered here in great detail.
How do you measure the memory usage of an application or process in Linux?
From the blog articl
Another vote for Valgrind here, but I would like to add that you can use a tool like Alleyoop to help you interpret the results generated by Valgrind.
I use the two tools all the time and always have lean, non-leaky code to proudly show for it ;)