Stack & amp; Heap in Java

Source: Internet
Author: User


Stack: The size and lifecycle of data stored in the Stack are determined, and the data in the Stack can be shared.
Heap: the memory size can be dynamically allocated without prior notice to the compiler lifecycle. The data in the Heap is also recycled from time to time by the Java garbage collector.

Integer a = new Integer (10 );
The new statement indicates that the data after the compiler needs to be dynamically created during runtime, so the data is stored in the heap.
Create an Interger object reference variable a in the stack

All Java objects are stored in Heap.

Features of Heap:
1) Heap is a general-purpose pool of memory (in the RAM area) where all Java objects live

2) Unlike the stack, the compiler doesn't need to know how long that storage must stay on the heap

The last reference is as follows:

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.