KMM: GC does not release memory - how to force it to release?


I’m developing a network extension on iOS and I want to use KMM to share some code between Android and iOS.

iOS is quite strict on RAM usage and it only provides 50 MB for network extensions. KMM does not release memory often/soon enough and iOS kills my app.

The problem seems to be the same as in this issue on github: [Multiplatform] K/N 1.3.31 vs 1.3.41+ iOS Memory Leaks? · Issue #3595 · JetBrains/kotlin-native · GitHub

I’ve tried calling GC.collect() but it does not seem to be available anymore.

Any solutions? Can I use KMM in low RAM environments?


  fun decodeJson(json: String) {
      val decodedJson = Json{ ignoreUnknownKeys = true }.decodeFromString<Json>(json)

Even though decodedJson is not referenced anywhere, KMM does not release the memory.

1 Like

I’m having the same issue. Did you ever find a solution?