Java Memory allocation

Source: Internet
Author: User

In order to improve the efficiency of the program, the Java program makes different spatial allocations to the data:

The specific partition is the following 5 memory allocation methods:

1. Stack: Local variables are stored

2. Heap: All new things are stored

3. Method Area:

4. Local Method Area: (and system-related)

5. Register: (CPU use)

Local variable: A variable in a method definition or a method declaration is called a local variable

Features of heap Memory:

1. Every new thing that comes out has an address value.

2. Each variable has a default value

Byte,short,int,long is 0

Float,double is 0.0

Char "\u0000" is equivalent to null

Reference type is NULL

3. It will become garbage when it is finished, but it will not be collected immediately, and may be recycled when the garbage collector is idle.

Features of stack memory:

Data is freed from scope

The value of the array name is the address, and the value of the array element (that is, the array name [index]) is the value that stores the data in the array.

int[] Arr3 = arr; This is the address of ARR to ARR3, now the same as the first address of ARR and ARR3.

ArrayIndexOutOfBoundsException: Array index out-of-bounds exception

Cause: A non-existent index was accessed

NullPointerException: null pointer exception

Cause: The value of the array name is null and no longer points to the address value. You also use the array name to access its elements.

Array property: Length, used to get the length of the array.

Format: array name. length

Java Memory allocation

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.