Memory guide
Kotlin on the JVM has a garbage collector, so you never think about who owns an object. Mini has none. Instead it gives you three tiers, and you choose per file (or per class) how much control you want and how much the compiler checks for you.
| Tier | You write | The compiler does |
|---|---|---|
| Managed (default) | ordinary Kotlin | reference counting; removes most of the counting work (RcOpt) |
| Allocators | context(arena) { ... }, Arena, Heap, Pool | places each allocation in the allocator in scope |
| Strict | @file:MemoryMode(Mode.Strict), @Owned, x.free() | proves that every allocation has an owner and is released exactly once, or refuses to compile |
This guide goes from the first to the last. Each page builds on the previous one.
- Managed by default: what you get for free, and when you want more.
- Allocators and context parameters: choosing where objects live.
- Arenas and Scoped allocators: everything dies together.
- Strict mode: turning the checker on.
- Ownership: owned and borrowed,
free(),use {}, moves. - Fields and containers: owned values inside objects.
- Lambdas and captures
- Threads and ThreadSafe
@NoAlloc
The reference is the memory model specification; every diagnostic has a page in the diagnostics reference.
Every Mini program is valid Kotlin
The memory features are not new syntax. Allocators are classes in the package mini.memory, ownership is expressed with annotations (@Owned, @Borrowed), free() and move() are ordinary extension functions, and allocator selection uses Kotlin's context parameters (context(a: Arena), Kotlin 2.2+). The whole test corpus is also compiled with the real kotlinc, so IDEs, formatters and highlighting work unchanged, and on the JVM the allocators are naive stand-ins.
How the samples are checked
Every listing in this guide is a file under website/samples/memory/, and CI runs the compiler on each of them. Accepted samples are built, run and compared with their expected output; rejected samples are verified with ./minic check against exactly the error code stated on the page.
Current status of Strict mode
The checker implements the rules of the specification (a few are deliberately approximate, see the limits on each page) and is tested against a corpus of 56 programs with expected diagnostics and 33 accepted programs. Programs that use Heap, Arena and Pool build and run natively (C and LLVM backends), so every accepted sample has a Run cell. Only the samples that use spawn stay check-only, because threads are not available yet.