What does creating an object do in memory?
1: Load the Person.class file of the specified location on the hard disk into memory first.
2: When the Main method is executed, the space of the Main method (stack-to-stack) is opened in the stack memory, and a variable p is assigned to the stack area of the main method.
3: Creates an entity space in the heap memory and assigns a memory header address value. New
4: Spatial allocation of attributes in the entity space, and default initialization.
5: Display initialization of the properties in the space.
6: The construction code block of the entity is initialized.
7: Call the constructor of the entity to initialize the constructor function. ()
8: The first address is assigned to P, and the P variable refers to the entity. (pointing to the object)
From the heap and stack function and the role of the popular comparison, the heap is mainly used to store objects, the stack is mainly used to execute the program .
Popular comparison, the heap is mainly used to store objects, the stack is mainly used to execute the program. Heap memory and stack memory, heap memory and stack memory can not be shared