Carlos
02/11/2025, 2:30 AMstd::__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:
@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!sergey.bogolepov
02/11/2025, 10:03 AMCarlos
02/11/2025, 10:17 AM2.1.10
- Also updated to the latest kotlinx-coroutines 1.10.1
and kotlinx-serialization-json 1.8.0
What seems to have worked though, not sure which change it was, but for anyone looking at this thread:
• + adding this new property on gradle.properties
kotlin.native.binary.gc=cms
• - removing this old one kotlin.native.binary.memoryModel=experimental
• Explicitly setting to null
all the big classes that took a long time to garbage collect from the Xcode Instruments profiler toolssergey.bogolepov
02/11/2025, 10:23 AM• - removing this old oneThis should not have any effect.kotlin.native.binary.memoryModel=experimental
• + adding this new property on gradle.properties
Yep, CMS should help with GC pauses. Though, I would be surprised if it makes that much difference :)kotlin.native.binary.gc=cms
• Explicitly setting toThat's an interesting idea! Does instances of these classes "cross" language border between Kotlin and Swift/Objective-C, and/or have properties that store Swift/Objective-C objects?all the big classes that took a long time to garbage collect from the Xcode Instruments profiler toolsnull
Carlos
02/11/2025, 1:58 PM