Skip to content

M0106: Individual free of a Scoped object ​

error

What it means ​

free() is called on an object of an arena, or an arena object is passed to an @Owned parameter (the callee could free it). Arena objects have no individual release: the whole arena dies together.

Minimal failing example ​

From the test corpus: compiler/testdata/memory/free_scoped.kt. The corpus expects 14:13: M0106 (the ^ comment in the source marks the column).

kotlin
// REJECT M0106: an arena object cannot be freed individually. Spec 2.4, 7.6
@file:MemoryMode(Mode.Strict)

package memory.free_scoped

import mini.memory.*

class Box(val v: Int)

fun main() {
    Arena().use { arena ->
        context(arena) {
            val b = Box(1)
            b.free()
//          ^ M0106
        }
    }
}

Compiler output ​

Generated by running ./minic check compiler/testdata/memory/free_scoped.kt (exit status 1).

text
$ ./minic check compiler/testdata/memory/free_scoped.kt
error[M0106]: arena object `b` cannot be freed individually
  --> compiler/testdata/memory/free_scoped.kt:14:13   freed here
   14 |             b.free()
      |             ^
  help: remove the `free()`: the arena releases it

note: M0106 (Individual free of a Scoped object): https://henryschwerdt.github.io/mini/reference/diagnostics/M0106

error: could not compile free_scoped.kt (1 error, 0 warnings)

How to fix ​

Remove the free(). The arena reclaims the object when it is closed. If an arena object has resources, call its close() directly (that does not release memory).

Corpus programs for this code ​

See also: Diagnostics overview and the memory guide.

Released under the Apache License 2.0.