[cairo] reference counting vs garbage collection
Keith Packard
keithp at keithp.com
Sun Jan 2 12:37:05 PST 2005
In my nickle binding, I'm creating garbage collected objects that wrap
cairo surfaces and contexts. This allows me to automatically destroy
surfaces which are no longer in use.
Cairo doesn't make this easy for some kinds of surfaces though; for png
and ps surfaces, there is a 'FILE' object which is referenced by these
surfaces and which must be fclose'd when the surface is finally destroyed.
Of course, each cairo_t object associated with the surface (either as
target or pattern) holds a reference to it, so the surface isn't really
destroyed until the cairo_t objects are also destroyed.
The problem here is that I have no idea which call to
cairo_surface_destroy actually cleans up the cairo internal state,
flushing the remaining output to the file and dropping the reference to
the FILE object.
So, if the surface is finalized before the cairo_t and I fclose the file
at that point, when the cairo_t gets finalized and the png library
attempts to write the file, I get a nice segfault.
I don't really know what would work best in this situation; either some
kind of callback (yuck) when the surface is actually destroyed, 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.
What have other garbage collected bindings done in this situation?
-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/c5d8d19b/attachment.pgp
More information about the cairo
mailing list