Skip to content
Source
Sign inSign up
Open History to see the last commit

useUiRuntimeMemoryWarningGc.ts

16 lines582 Bytes

1import { AppState } from "react-native";
2import { scheduleOnUI } from "react-native-worklets";
3​
4function collectUiRuntimeGarbage() {
5 "worklet";
6 const gc = (globalThis as { gc?: () => void }).gc;
7 if (typeof gc === "function") gc();
8}
9​
10/** iOS memory warnings collect only RN's heap; collect worklets too to release shadow nodes and serializables. */
11export function installUiRuntimeMemoryWarningGc(): () => void {
12 const subscription = AppState.addEventListener("memoryWarning", () => {
13 scheduleOnUI(collectUiRuntimeGarbage);
14 });
15 return () => subscription.remove();