go-text / typesetting

High quality text shaping in pure Go.
Other
98 stars 10 forks source link

It appears faceCache and metaCache in FontMap are never cleaned out nor is there an API to unload fonts #167

Open dweymouth opened 1 month ago

dweymouth commented 1 month ago

This means that if a (Fyne/Gio/etc) app uses a font once and doesn't need it anymore (ie it is not used within X minutes and we want to unload it), there is no way to unload the font from the app's memory space

benoitkugler commented 1 month ago

Yes, that is correct. I guess we haven't thought of cases where you know for sure that you won't need a font in the future (perhaps for a language change, or as you mentioned it, based on a timer). A rough workaround would be to change the FontMap entirely, but you would loose all the caching..

We should add some API to clear the FontMap, perhaps something like: ClearCache(face *Face) ?

dweymouth commented 1 month ago

I don't know what the naming should be, ClearCache sounds fine, or UnloadFace, or something similar. The idea at least for Fyne I think would be to eventually track when font faces were last used, and if they haven't been used in some minutes, unload/uncache them. For apps displaying arbitrary unicode strings coming from external content, it's often possible that a face is needed only to render a particular string, and then never again needed or not in a long while.