Is font face reference counting broken?
Andreas Falkenhahn
andreas at falkenhahn.com
Wed May 15 14:22:22 UTC 2024
Thanks, then the behaviour makes sense.
Is there any way to flush Cairo's font cache? I'm using a font saved to a temp file and I can't delete that temp file as long as it's still in use (Windows behaviour). So I'd really need to find a way to make Cairo release the hold onto the file so that I can delete the temp file.
On 15.05.2024 at 16:13 Behdad Esfahbod wrote:
> the font cache of cairo holds onto the face.
> behdad
> http://behdad.org/
> On Wed, May 15, 2024 at 8:00 AM Andreas Falkenhahn <andreas at falkenhahn.com> wrote:
> I've noticed that the font face reference counting behaves a little
> weird in Cairo. Take a look at this code:
>
> printf("REF COUNT A: %d\n",
> cairo_font_face_get_reference_count(fface));
>
> cairo_set_font_face(cr, fface);
>
> printf("REF COUNT B: %d\n",
> cairo_font_face_get_reference_count(fface));
>
> cairo_set_font_size(cr, 36);
> cairo_show_glyphs(cr, g, 1);
>
> printf("REF COUNT C: %d\n",
> cairo_font_face_get_reference_count(fface));
>
> cairo_destroy(cr);
> cairo_surface_destroy(surf);
>
> printf("REF COUNT D: %d\n",
> cairo_font_face_get_reference_count(fface));
>
> cairo_font_face_destroy(fface);
>
> printf("REF COUNT E: %d\n",
> cairo_font_face_get_reference_count(fface));
>
> This prints the following here:
>
> REF COUNT A: 1
> REF COUNT B: 2
> REF COUNT C: 4
> REF COUNT D: 3
> REF COUNT E: 2
>
> The values for ref count A, B, C are look correct AFAICS but what
> about the ref count value D? As you can see, I get 3 for ref count D
> but shouldn't this be back to 1 at this stage?
>
> Consequently, since ref count value D is still 3, the ensuing call
> to cairo_font_face_destroy() won't actually destroy the font face
> but just decrease its ref count to 2 but isn't this wrong?
>
> To me it looks like either cairo_destroy() or cairo_show_glyphs()
> don't unref the font face correctly. I'd expect that after
> cairo_destroy() returns the ref count should be back to 1, shouldn't it?
>
> Or am I doing/understanding something wrong here?
>
> I'm attaching the full little demo program.
>
> --
> Best regards,
> Andreas Falkenhahn mailto:andreas at falkenhahn.com
--
Best regards,
Andreas Falkenhahn mailto:andreas at falkenhahn.com
More information about the cairo
mailing list