Memory leak in `cairo_surface_create_similar_image()` for Xlib backend
Maybe related to #500 (at least it's in the same place in the code).
Unfortunately, I can't get this leak to show up in Valgrind, so here is a description of the situation.
When switching to GTK3, the code of gdk_cairo_set_source_pixbuf()
changed to use cairo_surface_create_similar_image()
(it used to use cairo_image_surface_create_for_data()
).
This change altered the behavior of Ristretto, Xfce's image viewer, so that it hardly releases any memory when switching from one image to another, and also at the very end of loading an image, where about 50% of the memory used to load the image was previously released. See https://gitlab.xfce.org/apps/ristretto/-/issues/62.
Investigating Cairo code, it appears that forcing the use of the generic function cairo_image_surface_create()
in cairo_surface_create_similar_image()
allows to recover the old memory behavior: release of 50% of the memory at the end of the load compared to the peak reached during the load, and release of almost everything at the time of the image change.
So when the target surface of a ctx
context is of type Xlib, it is possible to use a wrapper of this type:
cairo_surface_t *surface = cairo_image_surface_create (format, width, height);
cairo_t *cr = cairo_create (surface);
gdk_cairo_set_source_pixbuf (cr, pixbuf, pixbuf_x, pixbuf_y);
cairo_set_source (ctx, cairo_get_source (cr));
cairo_surface_destroy (surface);
cairo_destroy (cr);
That's what I'm going to do while waiting for something better, but there's probably something to fix here.