Re: Object Reference counting idea.



Miguel de Icaza <miguel helixcode com> writes:

> > The confusion among gtk_object_ref, bonobo_object_ref,
> > Bonobo_Unknown_ref and CORBA_Object_duplicate is already pretty bad.
> 
> Maybe we need to document this better:
> 

My comments below:

> 	gtk_object_ref: never use it with BonoboObjects.
> 
> 	CORBA_Object_duplicate does not achieve any real reference
> 	counts at all, it is an ORB internal for returning data.

Actually, if you are going to manipulate something directly as a
CORBA_Object, rather than as a BonoboObject *, you need to
CORBA_Object_duplicate whenever you ref. Bascially this reference
counts the client side stub object that proxies to the remote object;
it's important not to release it until the last user is done with it,
but also not to leak it.
 
> 	bonobo_object_ref refs a local BonoboObject.

Does that mean that it's illegal to call bonobo_object_ref on a
BonoboObjectClient? I've seen lots of code that does this. 

If it is in fact illegal, then it should fail; right now it seems to
work. The fact that BonoboObjectClient inherits from BonoboObject has
always sort of confused me; I don't quite get which BonoboObject calls
are legal on a BonoboObjectClient and which aren't. This is especially
true in cases where very similarly named calls exist for both, for
instance, `bonobo_object_client_query_interface'
vs. `bonobo_object_query_interface'. From reading the code, it seems that 

To clean this up all this up, I think the best approach is to make
BonoboObjectClient stop inheriting from BonoboObject. This particular
piece of inheritance violates the Liskov Substitution principle anyway
-- it's not the case that a bonobo object client IS-A or WORKS-LIKE-A
bonobo object server. If anything, the inheritance should be the other
way around, since you can always locally use a server like a client,
but the converse is untrue.

> 	Bonobo_Unknown_ref refs on a CORBA_Object.
> 

It refs the server on the remote side of the object, but not the local
proxy stub thing. So actually, as I understand it, you should hardly
ever use Bonobo_Unknown_ref, you should use bonobo_object_dup_ref (and
bonobo_object_release_unref). Otherwise, there is no way to do correct
memory management of the local parts of the CORBA_Object.


Anyway, having read over the code a bit, I realized I was wrong and
there are in fact 6 different ref/unref call pairs which you could
make on a bonobo object (some of which are illegal in some contexts):

* gtk_object_ref / gtk_object_unref
* bonobo_object_ref / bonobo_object_unref
* Bonobo_Unknown_ref / Bonobo_Unknown_unref
* CORBA_Object_duplicate / CORBA_Object_release
* bonobo_object_client_ref / bonobo_object_client_unref
* bonobo_object_dup_ref / bonobo_object_release_unref


Similarly, there are four different query_interface calls:

* bonobo_object_query_interface
* bonobo_object_query_local_interface
* bonobo_object_client_query_interface
* Bonobo_Unknown_query_interface


While I know there are good reasons for many of these in both cases,
the end result presents a very confusing picture to the
developer. Documenting the differences correctly would be a great
first step towards working on simplifying this.

Even if it's too late for GNOME 1.4, we need to work to make Bonobo
easier to understand and use for developers in the long run.

 - Maciej





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