Re: gtk_ui_manager_get_accel_group reference



On Fri, 9 Nov 2007 16:40:18 +0100 c f wrote:

Hi,

I'm not sure if the following problem is a bug in gtk or it is a
'feature':

Running the following code:

GtkUIManager *uiManager = gtk_ui_manager_new();
GtkAccelGroup *accelGroup = gtk_ui_manager_get_accel_group(uiManager);

g_object_unref(accelGroup);
g_object_unref(uiManager);

will result in an error message:
"GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT
(object)' failed"

this error message is given when the refcounter of the uiManager is
decreased. When  gtk_ui_manager_get_accel_group is called it gives
back a reference to the AccelGroup but the ref count of it is not
increased. And from the error message seams that the UIManager still
has a reference to the AccelGroup object and it tries to free it.

This code works correctly if I increment the ref count manually after
getting the pointer of AccelGroup.

Please could you help to identify if this is a bug or a feature?

Unfortunately gtk's function naming isn't well standardised.  In
general, foo_get_bar() (where bar is an object) will not increment the
refcount on the returned bar. If the caller is required to unref (or
otherwise free) the return value, this should be stated in the API
docs.  If nothing is stated, assume _get_bar()-type functions do not
require an unref/free.  (If nothing is stated and an unref *is*
required, file a documentation bug.)

        -brian



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