Glib::Binding's doc says it's destroyed when either object is, but it's not
The documentation in binding.hg
, as rendered here, states:
* A binding will be severed, and the resources it allocates freed, whenever
* either one of the Glib::ObjectBase instances it refers to is deleted,
* when unbind() is called, or when the Glib::Binding instance loses
* its last reference.
However, inside binding.ccg
, we see that instead:
// Override unreference() from ObjectBase.
//
// Why is this necessary? Because GBinding is an unusual kind of GObject.
// It calls g_object_unref() itself, if either the source object or the
// target object is finalized, almost like g_binding_unbind().
// But the GBinding object shall be destroyed when and only when the last
// reference from a Glib::RefPtr is dropped.
So, contradictory to what we tell users, a wrapped Glib::Binding
is only destroyed when all its RefPtr
s are, not when either the source or target object are.
I see two problems with this:
-
The documentation is wrong. This obviously just needs fixed. It looks like it was just lifted from the C documentation and added to, rather than being deleted from.
-
There is no way I can see (but I might be missing it) to have a wrapped
Glib::Binding
that does not (a) force me to keep around aRefPtr
to keep it alive or (b) leak if I add an extra->reference()
to avoid having to do that. I can't say 'add a reference to stay alive until one or both of the bound objects no longer are', because they don't trigger it to die when they do. Maybe I can add some horrible callback to hack around this, but maybe there's a nicer solution than that? What good can come from keeping it alive if either object no longer is?