Java basic data Type storage location

Source: Internet
Author: User

Memory mechanism:

The memory mechanism of Java is divided into heap memory, stack memory, method area and so on.

The difference between the two:

Heap memory primarily holds entity objects, which are used to hold new objects and arrays of entity objects that reference variables. Managed by the virtual machine automatic garbage collector.

Stack memory primarily stores variables of basic basic types.

The method area mainly stores a class template and a static method.

Different location of the declaration determines where to store

Declaring in a method (local variable): Allocating space to a variable in the stack when called, releasing the stack at the end, and embodying the limitations of the variable.

Declare in a class (member variable): The variable is stored in the heap due to the need for the cycle of the action. is not invalidated by method destruction, similar to global variables in C.

For reference variables, the value stored in the corresponding memory is a reference, which is the storage address of the object and is stored in the stack.

Java basic data Type storage location

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.