What occurs when object is created in Java?

后端 未结 5 411
情深已故
情深已故 2020-12-08 18:12

My teacher gave me a question:

\"What occurs when objects are created in Java\".

To the best of my knowledge, memory allocation

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-08 18:37

    While the JVM is running the program, whenever a new object is created, the JVM reserves as portion of the Heap for that object (where the object will be stored). The amount of Heap that gets reserved is based on the size of the object.

    The JVM maps out this segment in the Heap to represent all of the attributes of the object being stored. A reference (address in Heap) to the object is kept by the JVM and stored in a table that allows the JVM to keep track of all the objects that have been allocated on the Heap. The JVM uses these references to access the objects later (when the program accesses the object).

提交回复
热议问题