[cairo] destroying context and surface
psychon at znc.in
Sat Oct 20 07:09:24 PDT 2012
On 20.10.2012 15:15, Mike Gran wrote:
> A quick question.
> When creating a new image context, one first creates the image surface
> and then creates the cairo context from the surface.
> cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_A8, w, h); cairo_t *cr = cairo_create(surface);
> cairo_surface_destroy(surface); cairo_destroy(cr);
> So, when tearing down, does one first destroy the cairo context and
> then the cairo surface? Or is it better to first destroy the surface
> and then the context? Or does it matter?
> It if doesn't matter, would it matter if it were an Xlib surface instead?
Cairo uses reference counting. cairo_create() uses cairo_surface_reference() to
get a new reference to the surface. This makes sure that the surface stays alive
at least as long as the context.
So the order in which you destroy stuff doesn't matter, no matter which cairo
backend you use. You could even destroy the surface immediately after
- Buck, when, exactly, did you lose your mind?
- Three months ago. I woke up one morning married to a pineapple.
An ugly pineapple... But I loved her.
More information about the cairo