When dealing with iOS objects, is there a way to force dealloc/deinit of the object from the Kotlin side? Should I make my property nullable and set it to null? 😰
l
leandro
09/01/2023, 5:37 PM
i dont think so, i would say it's related to the memory model at runtime, but i'd be interested in confirming that 🙏
j
Jeff Lockhart
09/01/2023, 6:35 PM
Objects allocated in Kotlin will only be deallocated when Kotlin/Native's garbage collector releases them, which should be some time after it's no longer referenced and GC is next run.
n
natario1
09/01/2023, 6:42 PM
Thanks guys. So if my container class has a longer lifecycle, I do have to set the property to null in Kotlin, and iOS object dealloc will be invoked once the Kotlin garbage collector processes that reference. Please correct me if I’m wrong.
j
Jeff Lockhart
09/01/2023, 6:53 PM
That is what I'd expect the behavior to be. You can read more about the Kotlin/Native memory model and GC here.