How objects are stored in memory

Five areas of memory

Stack --- local variable, when the scope of the local variable is executed, the local variable will be recycled by the system immediately

Heap --- byte space manually requested by the programmer, Malloc calloc realloc

BBS segment-global variables and static variables that have not been initialized. Generally, they are recycled after initialization and transferred to the data segment.

Data segment (constant area)-global static variable constant data that has been initialized, it will be recycled when the program ends

Code segment-storage code, stored program code

Class loading

1. When creating, definitely need to access the class

2. Declaring a pointer variable of a class will also access the class

During the running of the program, when a class is accessed for the first time, the class will be stored in the code segment area in memory. This process is called class loading

Class loading is only done when the class is accessed for the first time. Once the class is loaded into the code, it will not be released until the end of the program.

 

Reference link:

https://blog.csdn.net/qq_36747738/article/details/70909796

Guess you like

Origin blog.csdn.net/Candyys/article/details/108843713