How much of an memory overhead is a `lateinit` pro...
# getting-started
k
How much of an memory overhead is a
lateinit
property compared to a regular value? Let's say a reference to an instance...
j
I think they are implemented using
null
vs non-null under the hood, so there should be no overhead. Maybe you might lose on some optimizations due to the fact that
lateinit var
is a
var
as opposed to a
val
- but that's not the lateinit's doing. And I don't believe it would make a measurable difference. All of this is speculation, though
e
yeah, it compiles to a nullable field with null-check on access
with getter/setter if public, and direct field access if private, like other vals/vars
k
cool, thanks, I feared it was more like an extra object under the hood...
e
lazy() creates an extra object, plus (by default) has synchronization, so that costs a bit more
1