Valgrind is a programmer tool that allows to track memory related errors in C and C++ programs. I'll spare you the introduction which you can find on the website.
This page includes some tips on how to proficiently use valgrind on gtk/gnome programs. Feel free to add your own tricks or expand the page with more detailed explanations.
Memcheck
Memcheck is the main valgrind tool, it allows to detect memory leaks and other memory management errors. To run a gnome program under memcheck run:
G_SLICE=always-malloc G_DEBUG=gc-friendly valgrind --tool=memcheck --leak-check=full --leak-resolution=high --num-callers=20 your-program &> dump
G_SLICE and G_DEBUG env vars make sure to turn off glib's memory optimizations, so that they do not confuse valgrind.
If the program you are debugging uses dynamically loaded modules with GModule (for instance it has a GModule based plugin system) you should use G_DEBUG=gc-friendly,resident-modules to make sure that the modules do not get unloaded and valgrind can retrieve the function names when writing its log.
It's a good idea to compile ORBit2 with --enable-purify when running GNOME apps under valgrind since that ensures that all data structures are fully initialized which in turn avoids many warnings about uninitialized variables in CORBA code.
After running the program you can inspect the log in the dump file. The log contains a list of memory related issues and in particular memory leaks. Memory leaks are marked in three ways: definitely lost, possibly lost and still reachable: for a start concentrate on the definitely lost ones, which are bits of memory leaked for sure. For each leak valgrind provides a backtrace which lets you pinpoint exactly where the leaks happens, in particular if your program was compiled with debugging symbols, valgrind will tell you the exact line and file of the leak.
Note: If your binary is really a libtool-generated temporary wrapper, the above command line will run valgrind on your shell which is probably not what you want. Say instead
G_SLICE=always-malloc G_DEBUG=gc-friendly libtool --mode=execute valgrind --tool=memcheck --leak-check=full --leak-resolution=high --num-callers=20 your-program &> dump
Ubuntu users can look at the Ubuntu documentation about Valgrind to know all the details to get Valgrind working.
Supression
JohanDahlin has begun the work to write a suppression file, you can find it here.
Use it by sending in --suppressions=gtk.suppression to memcheck
Massif
Massif is a memory usage profiler. See this page for an explanation of how to use it in GNOME.
Tough places
It can be tricky to get Valgrind to run on session-wide programs like Nautilus or gnome-panel. Here is how to do it.
