<< in-depth analysis of Javaweb Technology Insider >> Reading notes-JVM memory management 2

Source: Internet
Author: User

JVM Garbage Collection Policy

1. Static memory allocation and recycling

The memory space is determined at compile time, and the memory space is allocated once the program is loaded. After the program is finished, the corresponding stack frame is revoked, and the allocated static memory space is recycled.

2. Dynamic memory allocation and recycling

The program runs dynamically allocating memory space, which is collected by the garbage collector.

3. Garbage collector

A. Correct detection of garbage objects (key functions)

B. Releasing the memory space occupied by the garbage object

4. Generational-based garbage collection algorithm (hostpot)

Algorithm design ideas:

The objects are grouped by the length of their lifespan (young generation, old age), the newly created objects are allocated in the younger generation, and after several garbage collections, the objects that are still alive are divided into older generations. The collection of older generations is not as frequent as the younger generation, which reduces the number of objects to be scanned at each garbage collection. This improves the efficiency of garbage collection.

Generational-based pairs of structures

The JVM divides the entire heap into young, old, Perm, respectively, to hold objects of different ages.

    • Young area: It is divided into the Eden and survivor areas, the newly created objects are in the Eden area, and when the Eden Zone is full, the MINORGC is triggered, and the objects that are still alive in the Eden area are copied to one of the servivor areas. Another surviving object in the Servivor area is copied to this survivor to ensure that there is always an empty servivor area.
    • Old area: Servivor area of the object will be triggered MINORGC, the surviving object into the older area, the object in the Servivor area is enough, will be placed directly in the Lao area. FULLGC is triggered when the OID area is full, and the entire heap memory is recycled.
    • Perm Area: This place is basically the class object, if a class is loaded frequently may cause the perm area to be full, garbage collection in the perm area is also triggered by FULLGC.

Sun's recommendations for the different generations in the heap:

It is generally recommended that the size of the young area is 1/4for the entire heap, while the survivor area in the young area is generally set to 1/of the entire young area8

<< in-depth analysis of Javaweb Technology Insider >> Reading notes-JVM memory management 2

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.