# Testing the Kotlin Native memory model

DevFeed: [Testing the Kotlin Native memory model](<https://devfeed.tech/articles/testing-the-kotlin-native-memory-model-25954.md>)

Original publisher: [Read original article](<https://medium.com/@kpgalligan/testing-the-kotlin-native-memory-model-d3ccd2c2810f?source=rss-c2f810aa7890------2>)

Author: Kevin Galligan

Published: 2021-10-03T16:35:56Z

Content type: tutorial

Language: en

Sources: [Kevin Galligan](<https://devfeed.tech/sources/stories-by-kevin-galligan-on-medium.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Test automation](<https://devfeed.tech/topics/test-automation.md>), [CI/CD](<https://devfeed.tech/topics/cicd.md>), [Gradle](<https://devfeed.tech/topics/gradle.md>), [Open Source](<https://devfeed.tech/topics/open-source.md>), [Software Testing](<https://devfeed.tech/topics/software-testing.md>)

Tags: [bugs](<https://devfeed.tech/tags/bugs.md>), [github-actions](<https://devfeed.tech/tags/github-actions.md>), [gradle](<https://devfeed.tech/tags/gradle.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-multiplatform](<https://devfeed.tech/tags/kotlin-multiplatform.md>), [kotlin-native](<https://devfeed.tech/tags/kotlin-native.md>), [memory-model](<https://devfeed.tech/tags/memory-model.md>), [open-source](<https://devfeed.tech/tags/open-source.md>), [testing](<https://devfeed.tech/tags/testing.md>)

## AI overview

The article encourages Kotlin/Native library maintainers to test the experimental memory model and report bugs while it matures. Kermit runs three Gradle builds: its published Kotlin 1.5.31 setup, Kotlin 1.6.0-M1 with the strict model, and 1.6.0-M1 with `-Pkotlin.native.binary.memoryModel=experimental`. The Kotlin version can be overridden with `-PKOTLIN_VERSION=1.6.0-M1`. For that Kotlin milestone, the excerpt says GitHub Actions `macos-11` provides required Xcode 12.5, whereas `macos-latest` has Xcode 12.4. Kermit found a minor issue; the author says one successful test run need not remain enabled, though they expect to run both models for a while after 1.6.0 releases. A minimal sample project is offered for reproducing failures, with `ThreadHelper.doInBackgroundUnfrozen` for running code on another thread; bug reports should select Kotlin as the project.

## Source excerpt

Memory joke Kotlin/Native's strict memory model has been a common topic of interest and/or concern in the community for some time. The arrival of the new memory model will remove what many consider an adoption blocker. However, creating and testing a new memory model is a significant undertaking. It is tempting to wait until the new memory model is "ready", but the community can help accelerate the maturing of the platform by testing the new model and reporting bugs. We are starting to run our open source library tests against the new memory model. Just turning it on for Kermit found a relatively minor issue. If you publish a library, it would be great if you could turn on the new memory model and see if things work. Although everybody's config is different, here's how we do it. Kermit's Kotlin version is in the gradle.properties file. GROUP=co.touchlab VERSION_NAME=1.0.0-rc4 KOTLIN_VERSION=1.5.31 # etc... Kermit/gradle.properties at main - touchlab/Kermit That makes turning on the memory model simple. We can pass in a different Kotlin version and memory model flag, both as gradle properties. Currently we run tests 3 times. First with Kotlin 1.5.31, which is our published version. Then Kotlin 1.6.0-M1, but with the strict memory model, then Kotlin 1.6.0-M1 and the new memory model. In the Github Actions script, here are the lines: - name: Build run: ./gradlew build --no-daemon --stacktrace - name: Build 1.6 run: ./gradlew build -PKOTLIN_VERSION=1.6.0-M1 --no-daemon --stacktrace - name: Build 1.6 nmm run: ./gradlew build -PKOTLIN_VERSION=1.6.0-M1 \ -Pkotlin.native.binary.memoryModel=experimental --no-daemon \ --stacktrace Param -PKOTLIN_VERSION=1.6.0-M1 sets the Kotlin verison, and -Pkotlin.native.binary.memoryModel=experimental turns on the new memory model. Also FYI, macos-latest is a little old and has Xcode 12.4. macos-11 has Xcode 12.5, which is required for Kotlin 1.6.0-M1. Obviously, if you run those once and they work fine, you don't need to leave them on. We