Re: destroying context and surface
Uli Schlachter <[email protected]>
| Newsgroups | gmane.comp.lib.cairo |
|---|---|
| Message-ID | <[email protected]> |
Hi, 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 cairo_create(). Uli -- - 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. -- cairo mailing list [email protected] http://lists.cairographics.org/mailman/listinfo/cairo