Introduction to Java Memory

Source: Internet
Author: User

Java programs typically have three ways to allocate memory:

(1) Allocation from a static storage area. Memory is allocated at the time of program compilation, and the entire running period of the program is present in this block. For example, global variables.

(2) Create on the stack. In the execution function, the storage unit of local variables within the function can be created on the stack, which is freed automatically at the end of the function execution. Stack memory allocations are computationally efficient in the processor's instruction set, but the allocated memory capacity is limited.

(3) Allocation on the heap, also known as dynamic memory allocation. When the program is running, it uses malloc or new to request any amount of memory, and the programmer is responsible for freeing the memory with free or delete. The life cycle of dynamic memory is determined by us and is very flexible to use, but the problem is the most.

Introduction to Java Memory

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.