Structure of [stack, stack, and method area] Based on java, java
For more information, see JAVA stack, stack, and method area,
Method Area (non-heap): it is the memory area shared by each thread. It is used to store data such as class information, constants, static variables, and Code Compiled by the real-time compiler.
Java heap: it is the largest memory area managed by the virtual machine and a memory area shared by all threads. It is created when the virtual machine is started. The only purpose of this memory area is to store object instances, where almost all object instances allocate memory. Java heap is the main area for managing the garbage collector.
Java Virtual Machine Stack: The thread is private, and its lifecycle is the same as that of the thread. When each method is executed, a stack frame is created at the same time to store information such as the local variable table, operand stack, dynamic link, and method exit. Each method is called until the execution is completed, which corresponds to the process of a stack frame in the virtual machine from the inbound stack to the outbound stack.
Cainiao: I just learned java, heap, stack, static, code, and dizzy.
There are a lot of problems. You can go deep into Java Virtual Machine version 2 to solve your problem.
1. From the code above, zhangsan and car are in an aggregation relationship. Both objects are saved in the heap space. The zhangsan object in the heap has a car reference.
2. Human zhangSan = new Human (); is equivalent to creating a zhangsan instance. All three attributes are stored in the heap objects. Only references pointing to zhangsan are stored in the stack.
3. The local variable age is stored in the stack and belongs to the runtime data.
4. The static variable weight belongs to the instance variable. You can use it without creating an object. It is stored in the static storage area.
5. sayAge is stored in the method area. When jvm loads type information, it is loaded to the method area.
6. The main method can be regarded as a thread. Each thread corresponds to a stack. The main method is static. No object needs to be created, so it is not in the heap zone.
I hope the above will help you. If you do not understand it, you can continue communication.