Re: Proposal: Ref Counting Conventions



> 1. A function returning an object, either as the return value or
> by-reference, must always add a reference before returning.  (example:
> query_interface apparently does this)

It definetly does.

> 2. If a function is passed an object as an in/out and wishes to return a
> different object, the object that was passed in must be unref()'ed and
> the new object ref()'d before returning

I do not like this.  At least the part in which I am supposed to unref
something that was passed to me.  It breaks the convention that
you ref when you want to keep  a reference to an object.

In this case, if you want to return another object, that is just fine,
but you should not unref the one you got.  I believe this is a hack
around the standard for "refing everything you return" that you
propose above.

> 3. An object passed into a function needs only be ref()'d if the
> function wishes to retain a reference do it beyond the scope of the
> function call  (fairly obvious)

Yes.

> I'd like to suggest that these conventions be adopted by all
> interfaces.  Users of interfaces should never have to ask "Do I need to
> ref() this object that I got back from this function?"  or "Do I need to
> unref this object before passing it into this function?"

The first part makes sense.  The second does not make sense: unrefing
of an object reference should be treated as the reference being fully
non-functional, the equivalent plain C code would be:

	xx_unref (p);
	p = CORBA_OBJECT_NIL;

Passing "p" in this context is obviously broken.

> Reference counting bugs are frustrating and hard to find., but if we
> consistently follow the above conventions we may have fewer such bugs.

I am not entirely sure this will avoid the bugs.  I rather see well
documented interfaces that describe the precise nature of the returned
value and at the same time write some utility code in Bonobo that can
keep track of reference counting for us, and can detect reference
count leaks if possible.

Best wishes,
Miguel.




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