[cairo] reference counting vs garbage collection

Kristian Høgsberg krh at bitplanet.net
Wed Jan 5 11:03:46 PST 2005


Carl Worth wrote:
...
> 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?

I see one problem, not so much with the naming or which function does 
the unref.  The problem is that the FILE (or whatever resource) could be 
shared between several surfaces.  When you call create_similar, the PDF 
backend creates a new surface which references the same underlying FILE. 
  I'm actually wrapping the FILE in the internal cairo_pdf_document_t, 
which is ref-counted, but this means you'll have to call _finish for all 
surfaces sharing the same file.  However, the current clipping surface 
could be one of those surfaces and it's hard to get at.

cheers,
Kristian




More information about the cairo mailing list