Re: Object Reference counting idea.



Michael Meeks <michael helixcode com> writes:

> Hi Elliot,
> 
> On Tue, 10 Oct 2000, Elliot Lee wrote:
> > This (if you unref more times than you ref, things crash) isn't a
> > problem that needs to be solved, assuming your object impl deactivates
> > the servant on the unref that takes the refcount to zero.
>   
>         Somehow I disagree, or don't understand your point; consider this
> scenario:
> 
>         Local   Remote
>         ref
>         ref
>                 ref
>                 ref
>                 unref
>                 unref 
>                 unref   <-- Erroneous unref. [3]
>         unref           <-- Servant destroyed
>         unref           <-- crash here.

This skips over the initial ref the object is created with. Should
that be unref'd locally or remotely? One possible answer is "either",
but one ref's worth of fudge factor is a loophole big enough to drive
a truck through.

I guess you could create the object with one initial local ref and one
initial remote ref, and keep the two refcounts truly separate. The
drawback to this is that it will effectively break the API since an
extra local unref will be needed everywhere. (And it breaks it in a
way that's not detectable by the compiler, but introduces leaks if you
don't change your code).

Another possibility is to make the inital ref always considered a
remote ref. That would mean that if you wanted to remove the last ref
from the server side (maybe because you know the other side of the
connection died), you'd have to use Bonobo_Unknown_unref, whereas some
things use bonobo_object_unref to do that currently, so it would also
mean API breakage.

A variant of this solution is to add bonobo_object_local_{ref,unref}
and keep bonobo_object_{ref,unref} working as before. Then you don't
break any existing code, and anyone who wants to keep around refs that
can't be removed remotely has a way to do so. But you make the Bonobo
refcounting situation one pair of calls more confusing.

A third possibility is to make the initial ref always local. This
would mean that in the normal case you'd have to do a remote ref and
then a local unref on activation. This seems quite unappealing.

While I am not an advocate of designing everything in excruciating
detail before coding, reference counting is so fundamental that it's
worth doing some up-front thinking about the corner cases before
changing things. Do you have any comment about the tradeoff of the
various approaches above?

 - Maciej




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