icerockdev / moko-mvvm

Model-View-ViewModel architecture components for mobile (android & ios) Kotlin Multiplatform development
https://moko.icerock.dev/
Apache License 2.0
1k stars 95 forks source link

Append iOS-specific ability for memory collecting #23

Closed DevTchernov closed 4 years ago

DevTchernov commented 4 years ago

Same as follow:

actual open class ViewModel actual constructor() {
    ...
    fun collectMemory() {
        kotlin.native.internal.GC.collect()
    }
}
Alex009 commented 4 years ago

why you think that it should be in ViewModel? maybe just global fun in ios-specific part?

Alex009 commented 4 years ago

so i add GC.collect to onCleared of ViewModel in ios...it will be automatically

Alex009 commented 4 years ago

merged

schrulnz commented 2 years ago

I have a question about this: Why do you think GC.collect() is needed here? Isn't the garbage collection called automatically by Kotlin anyways?

Alex009 commented 2 years ago

hi. we found that GC of Kotlin/Native not syncronized with swift part memory management. it's bring us to high memory usage, when swift part have many object and K/N not call GC yet, because think that it can wait.

another reason is that in swift part ios developers sometimes use deinit function with some logic and expect that this logic will be called immediately but if object was catched by Kotlin/Native this call will be delayed, wait for GC.

with automatically call GC.collect we solve for us both problems