What is the recommended way to free allocated memo...
# kotlin-native
t
What is the recommended way to free allocated memory? I'm allocating memory in my init block and I'm wondering if I can define a dealloc method to free it when the class is destroyed?
j
Make your constructor take a MemorySegment and make it the callers problem
If it's an external C API, you could make your type AutoCloseable and once again make it your callers problem
t
Cool. Thanks for the advice!
l
There's also Cleaner for Kotlin/Native that will be called when the Kotlin object gets gc'ed.
👍 1
l
👍 3