[cairo] reference counting vs garbage collection

Keith Packard keithp at keithp.com
Sun Jan 2 16:51:22 PST 2005


Around 0 o'clock on Jan 3, Olivier Andrieu wrote:

> There could be two functions I think: _destroy (which should rather be
> named _unref) to manage the memory and _close to indicate that the
> file resource is not to be used anymore. That's more or less how GTK+
> work for instance and it works very well with language bindings.

I suggested just this in a later message; nice to know it's been done in 
another project with some success.

I've also kludged this in my nickle binding by tracking the same state 
that cairo does for png/ps surfaces--whether copy_page/show_page have been 
called--and doing precisely that as needed before closing the file.  This 
'works', but requires implicit knowledge of the situations where cairo 
would use the FILE during cairo_surface_destroy.  A more reliable 
technique would obviously be better.

> > I don't really know what would work best in this situation; either
> > some kind of callback (yuck) when the surface is actually
> 
> why `yuck' ? It's a perfectly fine solution (again that's how GTK does
> it, with signals).

Callbacks introduce all kinds of issues related to locking which we've 
almost entirely avoided in cairo.  As soon as you have callbacks, you have 
to know what it means to call back into the library from the callback.

The only callbacks we have at present are the path walking ones, and I'm 
pretty well convinced that we shouldn't have even these, preferring 
instead to have a function return the entire path in a single data 
structure.

-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/a54deeb6/attachment.pgp


More information about the cairo mailing list