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