The difference between heaps and stacks

Source: Internet
Author: User

Stack: Auto-Recycle

Heap: 1. Memory address 2. Initialize default value 3. Garbage collection mechanism

int a = 5; In the stack.

Int[] b =null; At this point, null means that no heap is pointed.

int [] c =new int[5]; Open a space in the heap. At this point, C refers to a memory address.

======================= Learning Dark Horse Java video Learning, speak very vivid, and wisp again. It's time to practice the guitar.

= = Below is the information found online

1. Before looking at the example, make sure you understand the following terms:

Stack : An area allocated by the JVM to hold actions and data references that are executed by the thread. The stack is a running unit, and a thread in Java will have a line stacks corresponding to it.

Heap : An area allocated by the JVM for storing data such as objects.

constant Pool : In the compile phase, a chunk of storage allocated in the heap to store an explicit string,float or integer. For example, String str= "abc"; The ABC string is explicitly declared, so it is stored in a constant pool

The difference between heaps and stacks

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.