In-depth understanding of Java garbage collection mechanism

Source: Internet
Author: User

Algorithms in the garbage collection mechanism:

1. Reference counting method: cannot detect a circular reference. If the parent object has a reference to a child object, the child object in turn references the parent object. In this way, their reference count will never be 0.

2 tag-purge algorithm: Scan from the root collection, tag the surviving object object, and then scan the unmarked objects in the entire space for recycling, causing memory fragmentation

3 marker-Collation algorithm : the tag-sweep algorithm is the same way to mark the object, but in the purge of different, after reclaiming the space occupied by the non-surviving objects, all the surviving objects will move to the left free space, and update the corresponding pointer, the object moved, so the cost is higher

4 copying algorithm : Overcomes the overhead of the handle and resolves the garbage collection of heap fragments, it divides the heap into object and free area polygons, and the program pauses execution during the switchover between the object face and the idle area

5 generation (generational) algorithm: objects of different lifecycles can take different recycling algorithms to improve recycling efficiency

A: Young generation: The goal of the young generation is to collect as quickly as possible those objects with short life cycles: Replication

B: Older generations: objects that survive in the young generation after n garbage collection are placed in the old age: older generations are suitable for use with the mark-and-sweep algorithm (or mark-erase-organize)

In-depth understanding of Java garbage collection mechanism

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.