[cairo] reference counting vs garbage collection

Keith Packard keithp at keithp.com
Tue Jan 4 20:19:57 PST 2005


Around 22 o'clock on Jan 4, Carl Worth wrote:

> It seems that any code that would be calling cairo_surface_close would
> immediately be following it up with cairo_surface_destroy, (since the
> surface is useless after that). And letting the user hold on to a
> useless object doesn't seem like a feature to me.

Sure, but 'cairo_surface_destroy' only does the 'close' piece on loss of
the last reference, so it's really hard for the application to know when
it's happened, unless it also tracks the reference count. That's the key
here -- my garbage collector finalizers call 'cairo_destroy' and
'cairo_destroy_surface', but there isn't any deterministic ordering between
them, so I really can't easily tell when the 'close' piece will be 
executed.  Having that deterministically called through an exposed API 
would solve the problem.

> If we did that, then I think all we'd need is a new function to
> replace current calls to surface_destroy that really just want to
> release a reference. Perhaps cairo_surface_unreference?

But if you do drop the last reference and the surface hasn't been 
destroyed, would cairo_surface_unreference do that?  If so, then it seems 
like we've got a reasonable solution, aside from the usurption of the 
'_destroy' name for a new task.

-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/20050104/2ae949c9/attachment.pgp


More information about the cairo mailing list