JavaScript reference to underlying native object in a Turbo Module #284
Unanswered
Zach-Dean-Attractions-io
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Your native module should hold a reference to |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
Suppose I am implementing a Turbo native module and as part of this I create some instance of a class in Kotlin(/Objective-C++)
I also have a TypeScript representation of this class
Then if I had some function in in TypeScript that returned
MyJSClass
via a turbo native module, I could just returnMyNativeClass.name
from the native code and then in TypeScript wrap it in a new instance ofMyJSClass
.However, this would then mean that the underlying instance of
MyNativeClass
that was created would be garbage collected since nothing is holding a reference to the instance of that class as only thename
property was returned.How would I go about maintaining the reference of the underlying
MyNativeClass
in TypeScript so that only when the reference is garbage collected in TypeScript does the underlying native value get garbage collected?Do I need to implement a
HostObject
in the C++ layer to maintain the reference?If this is possible I assume that this is only supported in the new architecture and the legacy architecture wouldn't support this? (Maybe it might on Android). (For React Native 0.76.0+)
Is there any documentation I can find on this?
Beta Was this translation helpful? Give feedback.
All reactions