[cairo] reference counting vs garbage collection

Owen Taylor otaylor at redhat.com
Wed Jan 5 08:02:12 PST 2005


On Tue, 2005-01-04 at 23:58 -0500, Carl Worth 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; for a
language
binding, reference counting (keeping memory alive) must be independent
from 
method called by the application.

How does the language binding handle:

 obj = cairo_surface_new()
 obj.destroy
 obj = None

 obj = cairo_surface_new()
 obj = None

It gets worse when you start passing cairo objects to GTK+ bindings and
so forth.

GTK+ has a somewhat complex system involving "floating reference counts"
which
makes things nice for C programming, which you might want to look up if
interested,
but I don't think that complexity is needed here. Just separate out the 
close/finish operation (don't call it destroy, it will confuse people)
out
from the reference counting. 

Regards,
					Owen

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.freedesktop.org/archives/cairo/attachments/20050105/9771ba29/attachment.pgp


More information about the cairo mailing list