Java Memory mode

Source: Internet
Author: User

The Java memory model, called JMM. JMM defines how the Java Virtual Machine (JVM) works in Computer memory (RAM).

Java memory allocations mainly include the following areas:

    1. Register: We can't control it in the program

    2. Stack: A reference to a primitive type of data and objects, but the object itself is not stored in the stack, but is stored in the heap

    3. Heap: Storing data generated with new

    4. Static domain: Static members that are stored in the object with static definitions

    5. Chang: Storing constants

    6. Non-RAM (random access memory) storage: Persistent storage space such as hard drives

Stacks in Java memory allocation

Some basic types of variable data and object reference variables that are defined in the function are allocated in the function's stack memory. When a variable is defined in a block of code, Java allocates memory space for the variable in the stack, and when the variable exits the scope, Java automatically frees the memory space allocated for the variable, and the memory space is immediately available for another use.

Heap in Java memory allocation

Heap memory is used to hold objects and arrays created by new. The memory allocated in the heap is managed by the automatic garbage collector of the Java Virtual machine.

In fact, the variables in the stack point to the variables in the heap memory, which is the pointer in Java!

Chang (Constant Pool)

Chang refers to some data that is determined at compile time and is saved in the compiled. class file. In addition to the constant values (final) that contain the various basic types defined in the code (such as int, long, and so on) and object types (such as strings and arrays), there are also some symbolic references that appear as text, such as:
The fully qualified name of the class and interface;
The name and descriptor of the field;
Methods and names and descriptors.
The virtual machine must maintain a constant pool for each mounted type. A constant pool is an ordered set of constants used by that type, including direct constants (String,integer and floating point constants), and symbolic references to other types, fields, and methods.

Reference Blog: https://www.cnblogs.com/SaraMoring/p/5687466.html

Java Memory mode

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.