[cairo] scaled_font lifecycle issue

Adrian Johnson ajohnson at redneon.com
Sat Apr 9 10:00:01 UTC 2016


On 06/04/16 18:29, Fred Bca wrote:
> Hi,
> 
> With the current implementation of scaled fonts, I am encountering
> lifecycle issues when using system fonts (HFONT on windows or
> CGFontRef on Mac) that are already managed by third party components.
> 
> Typically, I would expect that after the following code, the system
> font can be fully released (cairo not holding any reference to it
> anymore):, but it is not the case
> 
> // win32 example but same problem with other backends
> cairo_font_face_t* font_face=cairo_win32_font_face_create_for_hfont(my_hfont);
> cairo_set_font_face(ctx,font_face);
> cairo_destroy(ctx);
> // I want to be able to destroy the my_hfont object here - if I do it,
> subsequent calls to cairo using the same font face with same size will
> fail because the hfont has been kept in cache.
> 
> The problem lies in the _cairo_scaled_font_map cache that holds
> references to unused scaled fonts in the holdovers list, and in the
> mru_scaled_font. So even if the font is not used anymore, it will
> remain in this extra cache forever.
> 
> It is of course easy to fix this by completely removing the holdovers
> and mru cache (it works very well with the attached patch) but given
> the impact this is probably not a long term solution. I know that
> there are callbacks to be notified when fonts are actually destroyed,
> but it is not an option when font management is done by an external
> component (and anyway in this case it only happens when calling the
> cairo_debug_reset_static_data, so it will just leak in production
> code).

Maybe we need a font_face API function to make cairo drop a font from
the cache once the application drops all references to the font_face and
scaled fonts?



More information about the cairo mailing list