<div dir="ltr">the font cache of cairo holds onto the face.<div><br></div><div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">behdad<br><a href="http://behdad.org/" target="_blank">http://behdad.org/</a></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, May 15, 2024 at 8:00 AM Andreas Falkenhahn <<a href="mailto:andreas@falkenhahn.com">andreas@falkenhahn.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I've noticed that the font face reference counting behaves a little weird in Cairo. Take a look at this code:<br>
<br>
        printf("REF COUNT A: %d\n", cairo_font_face_get_reference_count(fface));<br>
<br>
        cairo_set_font_face(cr, fface);<br>
<br>
        printf("REF COUNT B: %d\n", cairo_font_face_get_reference_count(fface));<br>
<br>
        cairo_set_font_size(cr, 36);<br>
        cairo_show_glyphs(cr, g, 1);<br>
<br>
        printf("REF COUNT C: %d\n", cairo_font_face_get_reference_count(fface));<br>
<br>
        cairo_destroy(cr);<br>
        cairo_surface_destroy(surf);<br>
<br>
        printf("REF COUNT D: %d\n", cairo_font_face_get_reference_count(fface));<br>
<br>
        cairo_font_face_destroy(fface); <br>
<br>
        printf("REF COUNT E: %d\n", cairo_font_face_get_reference_count(fface));<br>
<br>
This prints the following here:<br>
<br>
       REF COUNT A: 1<br>
       REF COUNT B: 2<br>
       REF COUNT C: 4<br>
       REF COUNT D: 3<br>
       REF COUNT E: 2<br>
<br>
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? <br>
<br>
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?<br>
<br>
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?<br>
<br>
Or am I doing/understanding something wrong here?<br>
<br>
I'm attaching the full little demo program.<br>
<br>
-- <br>
Best regards,<br>
 Andreas Falkenhahn                          mailto:<a href="mailto:andreas@falkenhahn.com" target="_blank">andreas@falkenhahn.com</a></blockquote></div>