[cairo] reference counting vs garbage collection

Carl Worth cworth at cworth.org
Tue Jan 4 20:54:59 PST 2005


On Tue, 04 Jan 2005 20:19:57 -0800, Keith Packard wrote:
> 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.

Sorry. I didn't explain this properly.

What I'm thinking of now is to change _destroy to do the close piece
immediately and set the internal closed flag so that the memory can be
freed when the reference count bottoms out.

> Having that deterministically called through an exposed API 
> would solve the problem.

Yes. And I think that cairo_surface_destroy should be that entry point.

> But if you do drop the last reference and the surface hasn't been 
> destroyed, would cairo_surface_unreference do that?

Yes, it would have to.

>                                                      If so, then it seems 
> like we've got a reasonable solution, aside from the usurption of the 
> '_destroy' name for a new task.

Oh, but we still like API churn at this point, right? ;-)

I'm open to other naming schemes, but I do like the pairing of
create/destroy and reference/unreference as opposed to having
create/destroy and reference and close.

-Carl





More information about the cairo mailing list