-
Notifications
You must be signed in to change notification settings - Fork 40
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
Added disposing/release mechanism to the system #131
base: main
Are you sure you want to change the base?
Conversation
To make sure we free any underlying values due to the dreaded hermes GC issue where internally allocated memory is not calcualated when considering garbage collection we need to implement this ourselves. A shared value is now disposed and all resources allocated should be released. This is done through wrappers. When deleting argument wrappers we also release any resources. Fixes #129
- Added calling dispose from useSharedValue - Ran clang / cpp lint
Wait, how does this work? Do we need to manually call close/dispose now when we no longer need a value? |
No need for users to call dispose - but f.ex. in the |
How does that happen? |
Hey @chrfalch / @mrousavy any updates on this fix? I believe I'm dealing with a similar memory leak issue as mrousavy/react-native-vision-camera#1953 / #129. Much appreciated, thanks! |
Hey @chrfalch -- quick FYI I monkey patched these changes into our build and it worked great. Memory leak is no longer an issue on iOS (have not tested Android). We are officially unblocked with this patch, but would love to get this fix into main for others. Lmk how I can help, thanks! |
How is this PR related to facebook/hermes@aae2c42? |
Yes it is definitely related. If it will replace it or be used in addition is not yet clear. |
src/hooks/useSharedValue.ts
Outdated
// Free on unmount | ||
useEffect(() => { | ||
return ref.current?.dispose(); | ||
}, []); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That will immediately free the shared value, I think we only want to run this in the cleanup function of the useEffect hook, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely - this looks like the exact reason for having great people doing code reviews! Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fixed now.
To make sure we free any underlying values due to the dreaded hermes GC issue where internally allocated memory is not calcualated when considering garbage collection we need to implement this ourselves.
A shared value is now disposed and all resources allocated should be released. This is done through wrappers.
When deleting argument wrappers we also release any resources.
Fixes #129