Hi everyone :wave: I recently upgraded my Kotlin M...
# ios
c
Hi everyone 👋 I recently upgraded my Kotlin Multiplatform project from Kotlin 1.9.0 to Kotlin 2.x (to take advantage of some newer features and library compatibility). The shared code targets iOS, Android, and web. After the upgrade, my iOS app started to lag or even freeze for tens of seconds, during which Instruments shows the Kotlin GC (ConcurrentMarkAndSweep) taking huge amounts of CPU time:
Copy code
std::__1::invoke_result<kotlin::gc::ConcurrentMarkAndSweep...
kotlin::gc::mark::ParallelMark::parallelMark(kotlin::ParallelProcessor...
    Kotlin_processObjectInMark
    Kotlin_processArrayInMark
I see the memory usage spike, and the app is stuck until the GC finishes scanning. On Kotlin 1.9 the app is super smooth. One code change we made was removing explicit
freeze()
calls in a small Flow wrapper. For example, we used to do:
Copy code
@OptIn(FreezingIsDeprecated::class)
class FlowWrapper<out T>(...) {
  init { freeze() }
  ...
}
That’s gone because freeze is deprecated under the newer memory model. But I’m wondering if that might affect how large object graphs are pinned or scanned. Has anyone run into big GC stalls on iOS with Kotlin 2.x? If so, how did you handle it? Any help or tips would be awesome. Thanks! Slack Conversation