Debugging gobject reference leaks can be difficult, very difficult
according to the official documentation.
If you google this subject you will find numerous hits. A tool called
RefDbg was created to address this specific need.
It however appears to have lost effectiveness because (taken from the docs):
Beginning with glib 2.6 the default build does not allow functions to
be overridden using LD_PRELOAD (for performance reasons). This is the
method that refdbg uses to intercept calls to the GObject reference
count related functions and therefore refdbg will not work. The
solution is to build glib 2.6.x with the '--disable-visibility'
configure flag or use an older version of glib (<= 2.4.x). Its often
helpful to build a debug version of glib anyways to get more useful
stack back traces.
I actually tried the tool and got the error “LD_PRELOAD function override
not working. Need to build glib with –disable-visibility?” , so I kept looking.
Another post lead me to investigate using systemtap which seemed promising, so I looked into it further. This approach eventually got me the information I needed to find and fix reference count problems. I’m outlining what I did in hopes that it will be beneficial to others as well. For the record, I used this approach on storaged, but it should work for any code base that uses gobjects. The overall approach is: