Add hooks into HostObject destructors #46
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #10 .
According to The Big O of Code Reviews, this is a O(n) change.
This PR adds C++ destructor hooks from uniffi
interface
objects, to call the corresponding Rustdrop
methods.The impedance mismatch between a GC'd language and an RAII language means that one is a leaky abstraction for the other.
From facebook/hermes#982 (comment):
From the HostObject's destructor docs:
For this reason, the
uniffiDestroy
method is left in place for now: if you absolutely need to drop a Rust peer object, then you should call theuniffiDestroy
method of the correspond JS object.From the integration tests alone, it is difficult to show that this is working; they are too short-lived for the Runtime to be still running and garbage collection to have taken place.
However, the
test_callbacks.ts
did cause an ungraceful shutdown when the destructor called into Rust which then called back into JS– which had already been killed.The situation will only really get better when React Native/Hermes supports a robust
FinalizationRegistry
implementation.