Bug 4909 - g_object_remove_toggle_ref CRITICAL is printed (glib sharp master)
Summary: g_object_remove_toggle_ref CRITICAL is printed (glib sharp master)
Alias: None
Product: Gtk#
Classification: Mono
Component: gtk-sharp ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2012-05-06 19:10 UTC by Andres G. Aragoneses
Modified: 2012-05-25 08:56 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Andres G. Aragoneses 2012-05-06 19:10:08 UTC
When running Banshee with Gtk#3 I get this printed:

GLib-GObject-CRITICAL **: g_object_remove_toggle_ref: assertion `G_IS_OBJECT (object)' failed

I've tracked this down to the following reason: the finalizer on the object is being called twice, so not sure if the root cause of this is a Mono bug.

However, I have a patch ready for gtk-sharp to prevent this. I'll make a pull request now.
Comment 1 Andres G. Aragoneses 2012-05-06 19:32:01 UTC
Comment 2 Andres G. Aragoneses 2012-05-07 16:54:51 UTC
When I said "the finalizer on the object is being called twice, so not sure if the root cause of this is a Mono bug", I think I was actually wrong.

After digging a bit, I think I know what is happening. This is the Dispose() method in GLib.Object:

                protected virtual void Dispose (bool disposing)
                        ToggleRef tref;
                        lock (Objects) {
                                if (Objects.TryGetValue (Handle, out tref)) {
                                        tref.QueueUnref (this);
                                        Objects.Remove (Handle);

                        handle = IntPtr.Zero;
                        if (tref == null)

                        if (disposing)
                                tref.Dispose ();
                                tref.QueueUnref (this);

Somehow in my 32bits system, "if (tref == null)" is false, and in my 64bits it is true (and this may not be a bug, it may just be related to performance of the CPU, because my 32bits system is much older/slower).

So, since (tref == null) can definitely happen, I think the pull request https://github.com/mono/gtk-sharp/pull/39 is still valid.

PS: The reason I'm guessing it is performance-related is because the a TimeoutHandler is used in ToggleRef.QueueUnref():

if (!idle_queued){
        Timeout.Add (50, new TimeoutHandler (PerformQueuedUnrefs));
        idle_queued = true;
Comment 3 Andres G. Aragoneses 2012-05-25 08:56:54 UTC
This was finally a redundant call to QueueUnref, fixed here: https://github.com/mono/gtk-sharp/commit/85b84f99f651f2a640dad0ca62ce986b9bb57aa2