The kotlin native tutorial about dynamic libraries...
# kotlin-native
y
The kotlin native tutorial about dynamic libraries (https://kotlinlang.org/docs/tutorials/native/dynamic-libraries.html) has an example about the C++ code creating a Kotlin object instance and releasing it later:
Copy code
libnative_kref_example_Clazz newInstance = lib->kotlin.root.example.Clazz.Clazz();
  long x = lib->kotlin.root.example.Clazz.memberFunction(newInstance, 42);
  lib->DisposeStablePointer(newInstance.pinned);
What happens if instead I have the following Kotlin code:
Copy code
interface Foo {}

private class FooImpl : Foo {}

createFoo() : Foo { return FooImpl() }
and I call
createFoo
from C++ (in other words, the object is created on the Kotlin side not the C++ side). How do I tell the Kotlin side that I am going to keep the
Foo
instance for a while? Does it work the same and I am supposed to call
DisposeStablePointer
when I am done?
s
Does it work the same and I am supposed to call
DisposeStablePointer
when I am done?
Yes.