https://kotlinlang.org logo
g

Guilherme Delgado

04/08/2022, 7:30 PM
Anyone running into something similar? KMM - kotlin.native.concurrent.InvalidMutabilityException
m

Mikolaj Leszczynski

04/08/2022, 8:38 PM
Hey! This is to be expected with the current Kotlin Coroutines memory model. The moment an object (in this case your mutable list) is passed between different coroutines, it is frozen and cannot be mutated. Attempts to do so will cause exceptions such as the one you’re experiencing. The way around this particular problem, using Orbit, is to make that list part of the state. Reductions are not subject to mutability exceptions.
@Guilherme Delgado Please let me know if this works :)
Jetbrains is working on a new native memory model for KMM which will lift the requirements on object freezing, so should hopefully allow you to do these things in the future. Support is experimental currently.
Another approach is to use an
atomic
for the list
in case you don’t want to make this list part of the container state 🙂
g

Guilherme Delgado

04/08/2022, 8:55 PM
cool! Gonna try all and let you know 🙂 thanks for you reply @Mikolaj Leszczynski!
quick feedback (I don’t want that list to be part of the state), the only thing it made it work was enabling the new MM:
Copy code
kotlin.native.binary.memoryModel=experimental
👍 1
9 Views