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

refactor: explicit invalidations for native and cpp #6850

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tjzel
Copy link
Collaborator

@tjzel tjzel commented Dec 23, 2024

Summary

This pull requests refactors memory management of Worklets and Reanimated.

Basically, since Reanimated can obtain WorkletsModuleProxy and the Worklet Runtimes as shared pointers, it has to release them explicitly during the invalidation stage of Native Modules. Releasing them later on (e.g. via deconstructors) might lead into issues and crashes.

Ideally we'd instead use some different solution here than shared pointers, but it can wait as it's not mandatory at the moment and could be a significant refactor.

Fixes:

  • iOS crash on reload
  • Android crash on SingleInstanceChecker during third reload

Test plan

  • 0.76 iOS/Android Fabric works
  • 0.76 iOS/Android Paper works
  • 0.75 iOS/Android Fabric works
  • 0.75 iOS/Android Paper works
  • 0.74 iOS/Android Fabric works
  • 0.74 iOS/Android Paper works

explicit WorkletsModule(
jni::alias_ref<WorkletsModule::jhybridobject> jThis,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Turns out we don't need to keep the reference to Java part of WorkletsModule in cpp.

assertWithMessage(
instanceCount_ <= 1,
instanceCount_ < 1,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When cleaning during invalidation stage, it shouldn't be possible for two instances to exist at the same time.

@tjzel tjzel marked this pull request as ready for review December 24, 2024 13:24
@tjzel tjzel added the Check compatibility Trigger a time-consuming compatibility check action label Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Check compatibility Trigger a time-consuming compatibility check action
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant