NativeProxy and AndroidUIScheduler is a HybridClass with a C++ counterpart holding a global reference to the Java object. This structure creates a circular reference between C++ and Java, which the garbage collector cannot clean up. To resolve this issue, I manually removed the reference between C++ and Java by resetting the global ref during the invalidation of the NativeProxy and AndroidUIScheduler.
Test plan
I tested it with a new project using Expo (SDK 52) and with Fabric enabled. I reloaded the app several times and performed a heap dump to verify that everything was removed correctly.
Summary
Breaks circular reference in
NativeProxy
andAndroidUIScheduler
. Needs https://github.com/software-mansion/react-native-reanimated/pull/6671 to work.NativeProxy
andAndroidUIScheduler
is aHybridClass
with a C++ counterpart holding a global reference to the Java object. This structure creates a circular reference between C++ and Java, which the garbage collector cannot clean up. To resolve this issue, I manually removed the reference between C++ and Java by resetting the global ref during the invalidation of theNativeProxy
andAndroidUIScheduler
.Test plan
I tested it with a new project using Expo (SDK 52) and with Fabric enabled. I reloaded the app several times and performed a heap dump to verify that everything was removed correctly.