Search code examples
androidioskotlin-native

Kotlin/Native Garbage collection on iOS and Android


I need to develop a multiplatform module in Kotlin Native for iOS and Android. According to kotlinlang documentation:

Objective-C and Swift use reference counting. Kotlin/Native has it's own garbage collection too. Kotlin/Native garbage collection is integrated with Objective-C/Swift reference counting.

Does it mean that Kotlin/Native compiled for iOS does not use CMS (Concurrent Mark Sweep) and uses ARC(Automatic Reference Counting)?

Is it possible that common module which written in Kotlin and compiled for iOS might leak and the same module compiled for Android might be completely fine?


Solution

  • Kotlin/Native does not use Concurrent Mark-Sweep garbage collector even on Android. It uses an automated reference counter with a cycle collector to collect cyclical garbage (https://github.com/JetBrains/kotlin-native/blob/master/FAQ.md). So should behave more-or-less same way on both platforms.