signal disconnections for singleton objects

hi all-

i have a gobject class that works somewhat as a singleton object (actually,
there's a single instance per X screen, but, for all intents and purposes,
it's a singleton).  i'm storing the object in the GdkScreen object using
g_object_set/get_data().  my object has one signal, "changed".  here's the

i have a panel app (xfce4-panel, actually), that uses shared libs as plugins,
so the panel plugins (launchers, clock applets, etc.) run in the same process
space as the panel itself.  the panel creates its own instance of my object,
and attaches to the "changed" signal.  one of the panel plugins also creates
an instance of my object (which is, due to being a singleton, the same
instance as xfce4-panel holds, with its refcount increased).  the plugin also
attaches to the "changed" signal.

here's where the problem starts.  panel plugins are unloadable, and are
unloaded if they aren't being used.  if my plugin is unloaded, it will call
g_object_unref() to release its reference to my singleton object.  of course,
the panel itself has not dropped its reference, so the object is not
finalized.  what this means is that when the "changed" signal is fired, glib
will try to call both the panel's callback function, and the plugin's callback
function.  obviously, the plugin's function doesn't exist anymore, since the
plugin was unloaded, so the panel crashes.

the simple solution is just to require that anyone who attaches to the
"changed" signal must explicitly disconnect before calling g_object_unref().
however, this is pretty nonstandard and unusual, so i was wondering if there's
a way to hook into unref, or... something...  so i can somehow automatically
disconnect signals when someone drops their reference.

if you've made it this far, thanks for reading... ^_~


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]