Open
fix(Text): release cached font collection when no surfaces remain #3885
fix(Text): release cached font collection when no surfaces remain #3885
Open
you_yang_Add on 20 hours ago
you_yang_
you_yang_Collaborators
20 hours ago

锘縋artial backport of #3860 to 0.72-main (font-collection release only). Linked issue: #3535

Problem

On this branch TextMeasurer itself caches the OH_Drawing_FontCollection used for text measurement (there is no separate FontRegistry). When an app closes all RN surfaces while keeping the RNInstance alive, the cached collection stays resident on the native heap until instance teardown.

Scope

This is a reduced backport of #3860: on this branch the per-instance text measurement entry caches live in the global TextMeasureRegistry shared across instances, so trimming them from one instance's lifecycle would affect other instances. This change therefore only releases the per-instance cached font collection and leaves the global registry untouched.

Solution

  • TextMeasurer: add releaseCachedFontCollection() dropping only the measurer's cached reference under its mutex; registered font bytes are kept, so the next getFontCollection() rebuilds the collection lazily (same behavior as the existing registerFont replacement path). The underlying OH_Drawing_FontCollection is destroyed via its registered OH_Drawing_DestroyFontCollection deleter once the last reference goes away.
  • RNInstanceInternal: add releaseCachedFontCollection() forwarding to the measurer from the context container (find on the "textLayoutManagerDelegate" key), and call it in markSelfAboutToDestroyed().
  • RNInstanceCAPI: call releaseCachedFontCollection() in destroySurface() when the last surface is removed. No createSurface() hook is needed: the collection is rebuilt lazily on the next measurement.

The host gtest additions of #3860 are not ported because this branch has no host gtest infrastructure; the release logic mirrors the FontRegistry::releaseCachedFontCollection() implementation covered by rnoh_font_test on main.

Impact

Internal lifecycle management only; no public API, symbol or behavior difference for surfaces that stay open. Typography consumers holding shared_ptr copies of the collection are unaffected - releasing only drops the measurer's cached reference.

Test

  • Host gtest coverage for the same release logic exists on main via rnoh_font_test (PR #3860).
  • Device A/B verification of the same source logic on later branches (5 runs each): baseline keeps roughly 120 MB/instance resident after all surfaces are closed while the instance stays warm; with the fix the measurement caches and the cached font collection are released at last-surface close and rebuilt on the next surface open, with identical measurement results.
likedislike
Merge blocked
you_yang_you_yang_Collaborators
20 hours ago Added label: bug
you_yang_you_yang_Collaborators
20 hours ago Associated issue: [0.72-main] Cached font collection stays resident after all surfaces are closed
cpf-managercpf-managerCollaborators
20 hours ago Added label: AI检视中
you_yang_
you_yang_Collaborators
20 hours ago Comments:

start build

likedislike
openharmony_ci
openharmony_ciCollaborators
20 hours ago Comments:

感谢提交 Pull Requests!
Thanks for submitting a pull request.

likedislike
openharmony_ciopenharmony_ciCollaborators
20 hours ago Added label: dco检查成功
openharmony_ci
openharmony_ciCollaborators
20 hours ago Comments:

首次触发
门禁构建开始,包含静态检查、代码编译【rnoh_0.72-main编译】,预计在60分钟内完成,门禁结果会同步发送到注册邮箱。您可以通过如下链接跟踪门禁进展:http://dcp.openharmony.cn/workbench/cicd/detail/6aeda83e64650f998ba95499/runlist

likedislike
cpf-managercpf-managerCollaborators
20 hours ago Removed label: AI检视中
cpf-managercpf-managerCollaborators
20 hours ago Added label: AI已检视
openharmony_ciopenharmony_ciCollaborators
20 hours ago Added label: 编译成功
openharmony_ciopenharmony_ciCollaborators
20 hours ago Added label: 静态检查成功
openharmony_ciopenharmony_ciCollaborators
20 hours ago Test passed
openharmony_ci
openharmony_ciCollaborators
20 hours ago Comments:

代码门禁通过
您可以通过如下链接查看门禁报告:http://dcp.openharmony.cn/workbench/cicd/detail/6aeda83e64650f998ba95499/runlist

静态检查:

# check type result report
1 codeCheck pass >>>

编译测试:
# Device build result package
1 rnoh_0.72-main success >>>

likedislike