[cairo] reference counting vs garbage collection

Keith Packard keithp at keithp.com
Sun Jan 2 14:47:16 PST 2005


Around 14 o'clock on Jan 2, Ned Konz wrote:

> If we make it possible to disable the reference count - triggered destruction 
> in libcairo itself, then it would be possible for a GC'd client language to 
> handle finalization explicitly. It would be necessary to provide access to 
> the refcount, so that the client language could tell when the libcairo (or 
> other) references were all gone.

I don't mind having the GC'd language just hold a reference and release it 
in the finalizer, that seems equivalent to me.

Hmm.  Actually, I don't really care when cairo destroys the object; the
only thing that matters is when the underlying external object will no
longer be referenced.  For PNG/PS surfaces, I'm talking about the stdio 
file.

If we separated the notion of 'closing' a surface from 'destroying' it, we 
could have cairo shut the surface down and clean things up but leave the 
surface object hang around until the reference counts dropped to zero.

With this operation added, the surface finalizer would 'close' the surface 
and also call 'destroy' which (might) delete it.

> Then a separate "really destroy" function could be called as part of the 
> client language finalization that would clean up the internal state of the 
> libcairo objects.

The problem here is that I've got two objects -- a cairo_t and a
cairo_surface_t which are both exposed to applications.  The cairo_t 
references the cairo_surface_t, and I can't know in the surface finalizer 
whether all associated cairo_t objects have been finalized already.  I 
could track the list of all cairo_t objects with a reference to the 
surface and point them away from the surface in the surface finalizer, but 
that sure seems like a bad idea.

Any thoughts on a 'close' method for surfaces?

-keith


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20050102/298c5196/attachment.pgp


More information about the cairo mailing list