Skip to content

M0115: Arena object owns a foreign reference ​

error

What it means ​

An arena never runs dispose on its objects, so an object in an arena must not own anything that needs releasing. A reference-counted String, a Managed object, or a Heap/Pool object flows into an owning field of an arena object. String literals are static and allowed.

Minimal failing example ​

From the test corpus: compiler/testdata/memory/arena_owns_string.kt. The corpus expects 14:30: M0115 (the ^ comment in the source marks the column).

kotlin
// REJECT M0115: an arena object owns a refcounted String; the arena never releases it. Spec 2.4, 7.14a
@file:MemoryMode(Mode.Strict)

package memory.arena_owns_string

import mini.memory.*

class Label(val id: Int, val text: String)

fun main() {
    Arena().use { arena ->
        context(arena) {
            val s = 5.toString()
            val l = Label(5, s)
//                           ^ M0115
            println(l.id)
        }
    }
}

Compiler output ​

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

text
$ ./minic check compiler/testdata/memory/arena_owns_string.kt
error[M0115]: arena object `Label` would own a foreign reference in field `text`; the arena never releases it
  --> compiler/testdata/memory/arena_owns_string.kt:14:30   flows into an owning field of an arena object
   14 |             val l = Label(5, s)
      |                              ^
  help: declare the field `@Borrowed`, or allocate both objects outside the arena

note: M0115 (Arena object owns a foreign reference): https://henryschwerdt.github.io/mini/reference/diagnostics/M0115

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

How to fix ​

Mark the field @Borrowed (non-owning; you are then responsible for the lifetime), keep only primitives, literals and objects of the same arena in arena objects, or avoid the arena for this data.

Corpus programs for this code ​

See also: Diagnostics overview and the memory guide.

Released under the Apache License 2.0.