Memory Management in Kotlin/Native: The New MM
Explore the new Kotlin/Native memory manager, GC, and object ownership.
The Old Memory Model Problem
Kotlin/Native's original memory model (pre-1.7.20) was "immutable by default": objects had to be frozen before crossing thread boundaries. This made multi-threaded code cumbersome and incompatible with Kotlin coroutines semantics.
The New Memory Manager (1.7.20+)
Since Kotlin 1.7.20, Kotlin/Native uses a new garbage-collected memory model that mirrors the JVM/JS behaviour. Object mutation across threads is allowed by default. The freeze() / isFrozen APIs are deprecated and no-ops.
All lessons in this course
- Kotlin/Native Overview: Targets, Toolchain & Compilation
- Memory Management in Kotlin/Native: The New MM
- C Interop with cinterop and .def Files
- Kotlin/WASM: Compiling to WebAssembly for the Browser