Structure of [stack, stack, and method area] Based on java, java

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.