[cairo] reference counting vs garbage collection

Ned Konz ned at squeakland.org
Sun Jan 2 14:34:35 PST 2005


On Sunday 02 January 2005 12:37 pm, Keith Packard wrote:
> I don't really know what would work best in this situation; either some
> kind of callback (yuck) when the surface is actually destroyed, 

Which would be hard to do with Squeak, since it's not easily re-entrant. This 
would end up with a little callback function that would set a flag somewhere 
and then we'd have to check later. Not too much fun.

> or some 
> way of knowing whether a call to cairo_surface_destroy has actually
> destroyed the surface might work.  That would require some care on my part
> as things like cairo_destroy also call cairo_surface_destroy, but I think
> that could work.

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.

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.

After all, it seems a bit redundant to have two separate finalization schemes.

> What have other garbage collected bindings done in this situation?

Ignored it and hoped it would go away?

-- 
Ned Konz
http://bike-nomad.com/squeak/



More information about the cairo mailing list