Repository navigation
Conversation
Android 内存压力回调触发 RN Runtime 的垃圾回收,UI Worklet Runtime 仍可能持有已卸载的原生对象。模块启动后注册回调,经 JS 队列调度 UI Runtime 的回收,并在模块失效时注销。
|
No actionable comments were generated in the recent review. Walkthrough
Change: Bug fix Merge Risk:
|
Note
This pull request was authored by AI on behalf of @AuYuHui.
Summary
Refs #11501. Android forwards memory pressure to the React Native runtime, but objects held by the separate UI Worklet Runtime can stay alive until that runtime collects.
Once the UI runtime has started, the Android Worklets module registers for the same trim levels that trigger a React Native collection. It posts to the JS queue, then schedules native JSI collection on the UI runtime. This keeps collection outside the Android callback. Invalidation unregisters the listener and guards queued callbacks.
Test plan
Changelog and C++ formatting checks passed. The changed translation unit passed an Android arm64 syntax check, and the changed Kotlin file compiled against Android SDK 37 and React Native 0.88.1. A full Android build and device validation are pending.
Use the reproducer from #11501 with a release build of the PR. Run the animated and plain arms with
scripts/laps.sh animated 20andscripts/laps.sh plain 20on Android 13. Compare Native Heap Alloc before and after the script sendsRUNNING_CRITICAL, before pressing its manual GC buttons. The expected result is that the animated arm releases inactive native objects after trim and the manual UI GC button has less additional memory to release.On current Android versions, background the app and also exercise
TRIM_MEMORY_BACKGROUND. Check that a trim after a React Native reload reaches the new instance and that neither reload nor teardown crashes. Android 14 and later no longer naturally deliverRUNNING_CRITICAL; the shell command in the repro triggers it explicitly.Changelog