https://kotlinlang.org logo
l

Lucas Schiavini

04/08/2022, 3:09 PM
Anyone had problems using kotlin classes on a thread in swift, and having errors like : Uncaught Kotlin exception: kotlin.native.IncorrectDereferenceException: illegal attempt to access non-shared <object>@27c0f38 from other thread And after trying to annotate the class with either SharedImmutable or ThreadLocal getting -> @ThreadLocal is applicable only to property with backing field, to property with delegation or to objects
https://github.com/lschiavini/KmmKlibError check the concurrent branch to generate the problem
k

kpgalligan

04/08/2022, 3:31 PM
You need to freeze the class before passing it around threads outside of Kotlin.
l

Lucas Schiavini

04/08/2022, 4:39 PM
As in calling freeze() directly on Kotlin?
p

pguardiola

04/09/2022, 7:28 PM
You can also use coroutines and the new memory model and forget about freezing objects manually
❤️ 1
4 Views