JAVA garbage collection Summary

Source: Internet
Author: User

How can I determine whether an object is alive during JAVA garbage collection? One method is reference counting, but this method cannot solve the problem of circular reference. The other method is root set search, which searches for all reachable objects from the root set, the content of the root set includes all references in the stack, static attribute references and constant references in the method area, and so on.
Garbage collection algorithms include:
Mark clearing algorithm: leaves memory fragments;
Copy algorithm: You need to divide the Eden space and vor space. When clearing the Eden space, you need to copy the surviving objects to the same vor space. In case of insufficient vor space, you need to be guaranteed by the old age;
Mark Sorting Algorithm: similar to mark clearing, but the surviving object is sorted into a space segment, and the rest end is idle;
Generational collection: the new generation uses the replication algorithm and the old generation uses the token truth algorithm;
Garbage Collector:
New Generation of Serial, replication algorithm, single-thread garbage collection, stop user thread execution during collection;
ParNew generation, replication algorithm, multi-thread parallel garbage collection, stop user thread execution during collection;
Parallel Scanvenge new generation, replication algorithm, multi-thread Parallel garbage collection, stop user thread execution, achieve controllable throughput (throughput optimization );
In the Old age of Serial, single thread, marking sorting algorithm, stopping user thread execution during collection;
In the Old age of Parallel, multiple threads, marking algorithms, and stopping user thread execution during collection;
CMS, concurrent mark-swap, old generation, mark clearing algorithm, multi-thread parallel collection, concurrent execution with user threads, minimum pause of garbage collection; disadvantages: CPU is sensitive, floating garbage cannot be processed, space fragments are generated, and sometimes Full GC is triggered;
Configuration Policy for garbage collection:
Objects are preferentially allocated in Eden.
Large objects directly enter the old age;
The survival threshold of long-lived objects in the old age;
When a Minor GC occurs, it is used to predict whether the space in the old age can meet the guarantee requirements. If the guarantee requirements are not met, the worst case is Minor GC-> guarantee failure-> Full GC; if the guarantee failure is not allowed, Full GC is performed directly;

Related Article

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.