[cairo] bindings & memory management

Behdad Esfahbod behdad at behdad.org
Tue May 15 13:37:31 PDT 2007

On Tue, 2007-05-15 at 11:32 -0400, Tamas K Papp wrote:
> Hi,

Hi Tamas,

> I am writing Common Lisp bindings for cairo (cl-cairo appears to be
> dormant and no longer compiles).  As suggested in the manual, I don't
> want to expose the users to pointers and reference counts, but I don't
> know what's the best model for that.

Have you read the Bindings appendix of cairo's reference documentation?
It's shipped in the release tarball.

> Currently I am wrapping a class around cairo objects like cairo_t,
> which only contain a pointer, but I am not sure when I can destroy
> objects.
> Example:
> 1. surface is created, stored in a class
> 2. context is created from surface, stored in a class
> 3. can I destroy the surface now? My assumption is that the context is
> still referencing it, but that's ok for me, I just no longer need the
> surface explicitly.
> 4. when I am done with drawing on the context, can I just destroy the
> context and have the surface destroyed automatically?

Yes.  It's a simple reference counting scheme.  Like many other
languages and systems.

> Another quesion: when is the output "flushed", for example, for a PDF
> file -- when I destroy the context or when I destroy the surface?

When the surface is finished, which you can manually call with
cairo_surface_finish() or it will be automatically called when the
surface is being destroyed.

Have fun with cairo!


> Thanks,
> Tamas
> _______________________________________________
> cairo mailing list
> cairo at cairographics.org
> http://cairographics.org/cgi-bin/mailman/listinfo/cairo

"Those who would give up Essential Liberty to purchase a little
 Temporary Safety, deserve neither Liberty nor Safety."
        -- Benjamin Franklin, 1759

More information about the cairo mailing list