Java Virtual Machine JVM Java Heap method area Java stack

Source: Internet
Author: User

The Java heap is the closest memory space for Java applications.

Almost all objects are present in the heap. Java heap completely self-active management, through the garbage collection mechanism, the garbage object will voluntarily clean up. No explicit release is required.

Depending on the Java garbage collection mechanism. the Java heap may have different structures.

The most common is to divide the entire Java heap into the new generation and the old age. Almost the same as humans. Aging is likely to find God, the new generation of objects or older objects, old age to store older objects. The Cenozoic may be divided into the Eden ,s0 and S1 areas, thes0 District and the s1 Zone is also known as the From-to area. They are two equally sized and interchangeable memory spaces for example , as seen in:

In most cases. The object is first assigned to the Eden area, and once again the new generation is recycled, assuming that the object still exists, it will enter s0 or s1, and then not after a cenozoic recovery, age +1. when the object age reaches a certain condition, it will be aging into the old age.

The following simple example shows the relationship between the Java Heap,theJava method area, and the Java stack. The code is as follows:

Package Cn.xhgg.test;public class Heaptest {private int id;public heaptest (int id) {this.id = ID;} public void Show () {SYSTEM.OUT.PRINTLN ("ID:  " +id);} public static void Main (string[] args) {heaptest H1 = new heaptest (1); Heaptest h2 = new Heaptest (3); H1.show (); H2.show ();}}


Heaptest instance reference types are definitely allocated in the heap,H1,h2 Local variables are stored in the Java Stack, and point to two instances in the heap.

For example, as seen in:



Java Virtual Machine JVM Java Heap method area Java stack

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.