[cairo] reference counting vs garbage collection

Carl Worth cworth at redhat.com
Wed Jan 5 10:52:01 PST 2005


On Wed, 05 Jan 2005 11:02:12 -0500, Owen Taylor wrote:
> > On Tue, 04 Jan 2005 20:29:43 -0800, Keith Packard wrote:
> > > Here's what I think each function should do:
> > > 
> > >     _create	allocate object. Refcnt = 1.  Connect dependent objects
> > >     _ref	refcnt++
> > >     _unref	if (--refcnt = 0) { finalize dependent objects; free object }
> > >     _destroy	finalize dependent objects; _unref
> 
> I think making destroy unref in this manner is a serious mistake,
> because it makes things *very* hard for language bindings;

_destroy must unref since it's the balancing call for _create --- it's
our explicit destructor. It's not just a poorly named finish function.

> for a language
> binding, reference counting (keeping memory alive) must be independent
> from method called by the application.

I agree with that.

I guess my mental block is that I can't see why an application would
want to call a "finish" function. It sounds to me like, "Render this
object useless, but let me still hold on to it".

Regardless, it does seem easy enough to remove the conflation:

_create		Allocate object. refcnt = 1. Connect dependent objects
_reference	refcnt++
_finish		Finalize dependent objects
_destroy	if (--refcnt = 0) { _finish; Free object }

That maintains the pairing of _reference/_destroy as with the current
code. And it allows Keith to get deterministic finalization, (he just
needs to add a call to _finish before _destroy).

Anyone not satisfied with a scheme like that?

-Carl



More information about the cairo mailing list