@devries-cameron20 / t3code-1 / commits / c001e191a1
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(mobile): collect UI runtime garbage on iOS memory warnings (#16296)

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Julius Marminge committed Oct 7, 2026 at 22:48 UTC c001e191a19db32199ad75ccea219f729f9db7c4
2 files changed +27
apps/mobile/src/App.tsx
+3
@@ -23,6 +23,7 @@ import { appAtomRegistry } from "./state/atom-registry";
23 import { OverlayPortalHost } from "./components/OverlayPortal";
24 import { shouldHandleAppLink } from "./lib/appLinking";
25 import { useMobileNavigationTheme } from "./lib/useMobileNavigationTheme";
26 +import { useUiRuntimeMemoryWarningGc } from "./lib/useUiRuntimeMemoryWarningGc";
27 import { SubscriptionUsageCoordinator } from "./widgets/SubscriptionUsageCoordinator";
28 import { VoiceInputProvider } from "./features/voice-input/VoiceInputProvider";
29 import { GlobalVoiceInputControl } from "./features/voice-input/GlobalVoiceInputControl";
@@ -57,6 +58,8 @@ function SplashScreenCoordinator() {
58 }
59
60 export default function App() {
61 + useUiRuntimeMemoryWarningGc();
62 +
63 return (
64 <RegistryContext.Provider value={appAtomRegistry}>
65 <CloudAuthProvider>
apps/mobile/src/lib/useUiRuntimeMemoryWarningGc.ts new
+24
@@ -0,0 +1,24 @@
1 +import { useEffect } from "react";
2 +import { AppState } from "react-native";
3 +import { scheduleOnUI } from "react-native-worklets";
4 +
5 +function collectUiRuntimeGarbage() {
6 + "worklet";
7 + // Hermes exposes `gc` on the worklets UI runtime; skip quietly on runtimes that do not.
8 + const gc = (globalThis as { gc?: () => void }).gc;
9 + if (typeof gc === "function") gc();
10 +}
11 +
12 +/**
13 + * React Native only collects the main JS runtime on an iOS memory warning. The
14 + * worklets UI runtime is a separate Hermes heap that holds native shadow nodes and
15 + * serializables alive until its own GC runs, so collect it on the same warning.
16 + */
17 +export function useUiRuntimeMemoryWarningGc() {
18 + useEffect(() => {
19 + const subscription = AppState.addEventListener("memoryWarning", () => {
20 + scheduleOnUI(collectUiRuntimeGarbage);
21 + });
22 + return () => subscription.remove();
23 + }, []);
24 +}