Re: BonoboXObject refcounting



Michael Meeks <michael ximian com> writes:

>         Dude !? I don't quite understand what you mean by "you can't just
> block it". Unless things are substantialy different, you can simply
> override the finalize method and refuse to chain to your parent - just    
> like with GtkObject, which is essentialy what we do - keeping the
> GtkObject around until the ORB doesn't need it anymore.

No. You cannot do this. In GObject, "finalize" is _always_ a fatal action,
no matter what you do in your finalize method.

Look at g_object_last_unref() in glib/gobject/gobject.c:

====
static void
g_object_last_unref (GObject *object)
{
  g_return_if_fail (object->ref_count > 0);
  
  if (object->ref_count == 1)	/* may have been re-referenced meanwhile */
    G_OBJECT_GET_CLASS (object)->shutdown (object);
  
#ifdef	G_ENABLE_DEBUG
  if (g_trap_object_ref == object)
    G_BREAKPOINT ();
#endif	/* G_ENABLE_DEBUG */

  object->ref_count -= 1;
  
  if (object->ref_count == 0)	/* may have been re-referenced meanwhile */
    {
      g_signal_handlers_destroy (object);
      g_object_set_qdata (object, quark_closure_array, NULL);
      G_OBJECT_GET_CLASS (object)->finalize (object);
#ifdef	G_ENABLE_DEBUG
      IF_DEBUG (OBJECTS)
	{
	  G_LOCK (debug_objects);
	  if (debug_objects_ht)
	    g_assert (g_hash_table_lookup (debug_objects_ht, object) == NULL);
	  G_UNLOCK (debug_objects);
	}
#endif	/* G_ENABLE_DEBUG */
      g_type_free_instance ((GTypeInstance*) object);
    }
}
====

No matter what you do in your finalize method, g_type_free_instance() will
be called.

> > This is still not very nice, but it seems to work. Better ideas are
> > very welcome, I'm still a bit confused how this whole refcounting
> > stuff in Bonobo works.
>  
>         It is a matter of there being two ref counts, and syncing the
> ORB's count with the bonobo count to try and cause less confusion overall.
> Either way, my preferred solution is to split the CORBA_Object reference  
> out of BonoboXObject.

So should the CORBA_Object go into BonoboObject ?

-- 
Martin Baulig
martin gnome org (private)
baulig suse de (work)




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