I understand that in Kotlin(or Java) an object is a referenced type. i.e.
private var Object1: Obj1? = Obj1()
Here var Object1 is a reference(8 bytes) to the instance of class Obj1(on Heap).
Thus, If I have a class such as:
class SampleClass {
private var IntVal: Int = 0
private var FloatVal: Float = 0F
private var Object1: Obj1? = Obj1 ()
private var Object2: Obj2? = Obj2 ()
}
Where Obj1 & Obj2 are custom classes:
class Obj1 {
private var IntVal1: Int = 0
private var IntVal2: Int = 0
private var IntVal3: Int = 0
}
class Obj2 {
private var FloatVal1: Float = 0F
private var FloatVal2: Float = 0F
private var FloatVal3: Float = 0F
}
Can I say that the size of the object of the SampleClass will be equal to Size of IntVal (Int: 4bytes) + size of FloatVal (float: 4bytes) + size of two object reference i.e. 8*2: 16bytes.
Thus, no matter what the size of class obj1 & obj2 is, the size of SampleClass will always be fixed (32bytes) as it holds the reference of the obj1 & obj2 objects and not the actual objects themselves.
Let me know if my understanding is correct or not.