https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
c

coolcat

06/25/2020, 3:32 PM
Can someone explain me something? I am using Kotlin on iOS and trying to implement an MVP architecture. I use a
WeakReference
to hold a reference to a View object from Kotlin, to try and avoid memory leaks. But these objects do not seem to get deallocated immediately when they go out of scope. This is annoying for me as I use iOS
UIViewController
as the view object, and the expectation is that these will have
deinit
called as soon as they are dismissed. I have tried the project
icerockdev/moko-mvvm
. In their iOS sample project
sample6
, the memory leak does not seem to occur, and the view has
deinit
invoked immediately. I have read the
moko-mvvm
source code and I think their implementation is the same as mine. I can’t understand this.
w

wingchi

06/25/2020, 7:06 PM
You can manually set that reference to
nil
in Swift when your
ViewController
calls
deinit
if that’s a concern for you.
c

coolcat

06/26/2020, 6:07 AM
The ViewController’s
deinit
is never called because my Kotlin class is clinging on to a reference to it.
p

Peter Hsu

06/28/2020, 11:38 PM
Perhaps it's working as expected? https://github.com/JetBrains/kotlin-native/issues/3437. Do your VCs eventually get deallocated, or did you verify you actually had a memory leak?
5 Views