[Gtk-sharp-list] refcounting, GC, and glade..

Vladimir Vukicevic vladimir@pobox.com
11 Oct 2002 21:55:25 -0700

I'm having an issue now that has me a bit stumped.  I have a chunk of
code that does the following:

    Console.WriteLine ("SetCustom");
    Glade.XML.SetCustomHandler (new Glade.XMLCustomWidgetHandler
(customWidgetHandler)); // note -- this function isn't defined in CVS,
i've got a patch against the XML.custom file; it's just

    Console.WriteLine ("New");
    gxml = new Glade.XML (null, "mphoto.glade", null, null);
    Console.WriteLine ("Autoconnect");
    gxml.Autoconnect (this);
    Console.WriteLine ("Autoconnect done");

Now, I added a WriteLine statement in Glade.XML:~XML() to print when
it's being called.  Running this, I see that it's being called from GC
while the app is in Autoconnect.  This means that the gxml object, that
I have a reference to, is being GC'd.. I find this to be rather odd. :) 
Doing some more gdb work I see that the object gets destroyed after the
first signal is connected.

This does not happen if there's no customWidgetHandler defined (note --
this just creates the appropriate Gtk.Widget based on a string and
returns it, and keeps a reference to each widget created even).  It also
doesn't happen if there -is- a customWidgetHandler, but Autoconnect
isn't being called.  So some combination of those two is causing this. 
Is this simply some memory corruption somewhere?  I guess either the
autoconnection code or the custom widget creation code could be doing
something strange, but they're hard to debug since they're in C#.. in
any case, I can't think of any reason other than corruption that could
cause this, no?

	 - Vlad

Vladimir Vukicevic <vladimir@pobox.com>