Garbage collection mechanism

Source: Internet
Author: User
In reading "Thinking in Java", simply record the type and rationale of the garbage collection mechanism. 1, reference count each object has a reference counter, when the reference is connected to the object, reference counter +1, when the reference leaves the scope or null, reference counter-1. When the counter is 0 o'clock, the space occupied by the object is freed. Flaw: If an object has a circular reference, "the object should be recycled, but the counter is not 0". 2. Stop-Copy (stop and copy) pauses the running program (not in background recycle mode), copies all surviving objects from the current heap to the other heap, and is not replicated is garbage. When an object is moved to another heap, they are next to each other and can simply allocate new space, and all references to those objects are corrected. 3. Mark-Sweep (Mark and sweep) iterates through all references to find all surviving objects. If the object survives, a tag is set. The cleanup action will not begin until all markers are complete. The garbage collector periodically conducts full cleanup actions, in which Java virtual opportunities are monitored, and if the object state is stable, the garbage collector becomes inefficient and switches to tag-sweep mode. If there is a lot of fragmentation in the heap space, it switches to stop-copy mode. This is the adaptive feature of the garbage collector. The Java Virtual machine can also use the JIT compiler technology, you can translate all or part of the program into machine code, improve the speed of the program.

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.