Does Kotlin save value of val property in RAM using property accessors?

Hello! Does Kotlin save value of val property in a computer memory? So, i know about property accessors Kotlin defines ones by default. I have information that the property accessors computed at the time of each access. Does default implementation of val property accessor store a value in a backing field? Should i provide my own implementation of a get property accessor to not store it in a memory?

For example, i have:

class Class {
    val propertyA: Int = 23
    
    val propertyB: Int
        get() = 23
}

Does both properties have same behavior under hood?

propertyA creates a backing field (so it consumes memory), propertyB doesn’t.

2 Likes