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

Source: Internet
Author: User
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

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.