Re: Circular reference problem



Nat Friedman <nat@helixcode.com> writes:

> There shouldn't be a circular ref loop.

I'm quite certain there is.

> BonoboWidget holds a ref on the ControlFrame, which holds a ref on the
> control, which holds a ref on its widget, and down the line.

BonoboWidget is not really relevant to my life in Nautilus, but even
so this is not a complete view.

> The problem is basically that we need to make sure that the
> ControlFrame unrefs the control before it goes away.

It does. But if you are trying to actually refcount the ControlFrame
instead of doing esxplicit destroys, and the Control is still holding
a ref, it will bever go away!

> (I assume you are talking about Bonobo ref counts here, and not corba
> object dups)
> 

I am pretty certain the Control holds a ref on the ControlFrame and so
there is in fact a circular ref loop. Are you suggesting this is a
bug?  I actually think it is correct to hold a ref on the ControlFrame
interface here, since the Control will feel free to make calls on it
as long as I think it's live. 

So I think the bonobo_control_frame_unbind_from_control() solution I
suggested is the best. As in other refcounted languages, you need a
mechanism to break circular refs explicitly.  I will prepare a patch
along these lines for the list's benefit.

See below for proof:


void
bonobo_control_set_control_frame (BonoboControl *control, Bonobo_ControlFrame control_frame)
{
	CORBA_Environment ev;

	g_return_if_fail (BONOBO_IS_CONTROL (control));

	CORBA_exception_init (&ev);

	Bonobo_Unknown_ref (control_frame, &ev);
        ^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^

	control->priv->control_frame = CORBA_Object_duplicate (control_frame, &ev);
	
	CORBA_exception_free (&ev);

	gtk_signal_emit (GTK_OBJECT (control), control_signals [SET_FRAME]);
}





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