fix(mobile): collect UI runtime garbage on iOS memory warnings (#16296)
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
1 parent
6c1ce06996
commit
c001e191a1
2 files changed
+27
No files matched your search
@@ -23,6 +23,7 @@ import { appAtomRegistry } from "./state/atom-registry";
|
||||
import { OverlayPortalHost } from "./components/OverlayPortal";
|
||||
import { shouldHandleAppLink } from "./lib/appLinking";
|
||||
import { useMobileNavigationTheme } from "./lib/useMobileNavigationTheme";
|
||||
import { useUiRuntimeMemoryWarningGc } from "./lib/useUiRuntimeMemoryWarningGc";
|
||||
import { SubscriptionUsageCoordinator } from "./widgets/SubscriptionUsageCoordinator";
|
||||
import { VoiceInputProvider } from "./features/voice-input/VoiceInputProvider";
|
||||
import { GlobalVoiceInputControl } from "./features/voice-input/GlobalVoiceInputControl";
|
||||
@@ -57,6 +58,8 @@ function SplashScreenCoordinator() {
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
useUiRuntimeMemoryWarningGc();
|
||||
|
||||
return (
|
||||
<RegistryContext.Provider value={appAtomRegistry}>
|
||||
<CloudAuthProvider>
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { useEffect } from "react";
|
||||
import { AppState } from "react-native";
|
||||
import { scheduleOnUI } from "react-native-worklets";
|
||||
|
||||
function collectUiRuntimeGarbage() {
|
||||
"worklet";
|
||||
// Hermes exposes `gc` on the worklets UI runtime; skip quietly on runtimes that do not.
|
||||
const gc = (globalThis as { gc?: () => void }).gc;
|
||||
if (typeof gc === "function") gc();
|
||||
}
|
||||
|
||||
/**
|
||||
* React Native only collects the main JS runtime on an iOS memory warning. The
|
||||
* worklets UI runtime is a separate Hermes heap that holds native shadow nodes and
|
||||
* serializables alive until its own GC runs, so collect it on the same warning.
|
||||
*/
|
||||
export function useUiRuntimeMemoryWarningGc() {
|
||||
useEffect(() => {
|
||||
const subscription = AppState.addEventListener("memoryWarning", () => {
|
||||
scheduleOnUI(collectUiRuntimeGarbage);
|
||||
});
|
||||
return () => subscription.remove();
|
||||
}, []);
|
||||
}
|
||||
Reference in new issue
Block a user