Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Break circular reference in LayoutAnimation #6671

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lukmccall
Copy link
Member

Summary

Breaks circular reference in the LayoutAnimations.

LayoutAnimations 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 destructor of the NativeProxy.

Test plan

  • tested in Expo Go ✅

@@ -110,6 +110,8 @@ NativeProxy::~NativeProxy() {
// has already been destroyed when AnimatedSensorModule's
// destructor is ran
nativeReanimatedModule_->cleanupSensors();

layoutAnimations_->cthis()->invalidate();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been dealing a lot with missing invalidations in #6850 and I have some thoughts.

Shouldn't we call it from Java when Native Modules are invalidated, for a more transparent flow?

(java)ReanimatedModule.invalidate() -> ... -> (java)NativeProxy.invalidate() -> (hybrid)LayoutAnimations->invalidate()

I don't think that relying on Native Proxy's destructor is the best choice here. On the other hand, this is safer since NativeProxy can be "safely" used until it's destroyed.

What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants