He can adjust the priority of memory usage based on dynamic, therefore, it is low in memory to a certain extent, will run automatically, enabling the recovery of memory, this is the garbage collection time uncertain reasons. We started this service is not automatically started.Simple but very slow, can not handle the case of a defect is circular references.
How it works: This object has a reference, not only increasing a counter, deleting a reference to reduce a counter, garbage recycling, recovering only counter 0 objects, this algorithm is the most deadly is unable to handle case of circular references.
Clear labeling algorithm is divided into "mark" and "clear" two stages: first mark all objects need to be recovered, all unified object is marked recovery after labeling is complete.
The reason that he is the most basic collection algorithm, because subsequent collection algorithms are based on this idea and improving its deficiencies obtained.
It has two main problems:
1. Efficiency is a problem, mark and sweep efficiency of the two processes is not high
2. Another problem is the space, a large amount of memory fragmentation discontinuous cleared after labeling, may cause too much space debris when the program is running during later need to allocate a larger target, I can not find enough contiguous memory and had to trigger another garbage collection operation in advance.

In order to address efficiency issues, collection algorithm called "copy" (Copying) appeared, according to the available memory capacity it is divided into two equal size, uses only one of them. When this piece of memory is used up, it will be copied to another piece of living objects above, then put the memory space has been used once cleared away. So that every time zone for the entire half-memory recovery, also do not consider the complexities of memory chips and other memory allocation. Long as the mobile heap pointer, in order to allocate memory, simple, efficient operation. But the cost of this algorithm is to reduce memory by half.
Copy the object collection algorithm in high survival rates when necessary to carry out more copy operations, efficiency will be low. More to the point, if you do not want to waste 50% of the space, you need the extra space allocation guarantees in response to the memory used by all objects are 100% survival in extreme cases, it can not be directly in the old general's choice of this algorithm. According to the characteristics of old age. It was proposed another "mark - finishing" (Mark-Compact) algorithm, the process is still marked with "mark - sweep" algorithm the same, but the subsequent steps are not directly recycled objects to clean up, but to all surviving objects move to the end, then clean out directly to end border unexpected memory.

This algorithm and no new ideas, just depending on the survival period of the object, the memory is divided into a few pieces. The java heap is generally divided into the old and the new generation's, so that you can eradicate the characteristics of each era to take the most appropriate collection algorithm. In the new generation, each garbage have found a large number of dead objects, only a few survive, then copy the selection algorithm, only need to pay the cost of reproduction of a small amount of live objects can be done to collect the recovery. The old era because of the high survival rate of the object, there is no extra space is allocated to its guarantee, you must use the "mark - clean-up" or "mark - finishing" algorithm to recover.
Serial collector
Using a single thread to handle all the work of garbage collection, because no interaction multithreading, so more efficient. However, you can not use the advantage of multiple processors. Therefore this collector for a single processor machine. On multiprocessor machines, of course, this collector may be used in a small amount (about 100M) the case can be used -XX: + UseSerialGC open.
Parallel collector
The young generation of parallel garbage collection, thus reducing garbage collection time, generally on a multi-threaded multiprocessor, use -XX: + UseParallelGC open. Old generation parallel collection. If you do not use the old generation concurrent collection, it is single-threaded garbage collection, thus restricting the ability to expand the use -XX: + UseParallelOldGC open.
Use -XX: ParallelGCThreads = number of parallel disposed garbage collection threads, this value can be set equal to the number of machine processing.
This collector may be configured as follows:
largest garbage collection Pause: The maximum pause time garbage collection time specified by -XX: Specifies MaxGCPauseMillis =. Is the number of milliseconds, if this value is specified, heap size and garbage collection-related parameters will be adjusted to achieve the specified value. This value may reduce throughput applications. Throughput: throughput garbage collection time and the ratio of the non-time garbage collection. By -XX: GCTimeRatio = set, formula 1 / (1 + N), for example, -XX: GCTimeRatio = 19, it means that 5% of the time for garbage collection, default is 99, only 1% of the time for garbage collection.
Concurrent collector
Can guarantee that most of the work performed concurrently (the application does not stop), garbage collection pause only very little time, this collection is suitable for relatively high response time requirements of medium and large applications, use -XX: + UseConcMarkSweepGC open.
Concurrent collector of old generation is mostly reduced pause time, he uses a separate garbage collection thread in the case of the application does not stop, track up objects in each old generation garbage collection cycle, the concurrent collector will collect in the early a brief pause for the entire application, the collection will be suspended once again, the second time will pause longer than the first time, multiple threads at the same time garbage collection work in the process.
Concurrent collector using processor time in exchange for a brief pause, a system on N processors, using concurrent collection portion K / N processors are available for recycling, in general, 1 <= K <= N / 4
Use concurrent collector in only one host processor mode is set to incremental mode can be obtained a shorter dwell time.
Floating garbage: Because garbage collection while the application is running, so some garbage collection may be generated when garbage collection is completed, thus causing the "floating Garbage", the garbage needs to recover off at the next garbage collection cycle, so the concurrent collection typically 20% of the reserved space required for the floating garbage.
Concurrent Mode Failure: concurrent collector application is running in the collection, so it is necessary to ensure that garbage collection heap at this time there is enough space for the program, otherwise, garbage collection has not been completed, the first heap space is filled with this will happen "concurrent mode failure" in the case, then the entire application will be suspended. Garbage collection.
Start concurrent collector: Because the application runs concurrent collection in the collection, pajamas must ensure that there is complete before collecting enough memory space used by the program, there would be "Concurrent Mode Failure", by setting the -XX: CMSinitiatingOccupancyFraction = specify how many concurrent started to collect the remaining pile.
Parallel: multiple events occur at the same time, do more things at the same time
Concurrency: a plurality of events occur in the same time interval. Every year in November. 11th carnival, the largest number in one day accept.

Article Directory GC jdk1.7 jdk1.8 Heap memory tuning Automatically trigger garbage collection Three GC algorithm Replication algorithm Advantages and disadvantages scenes to be used component Clear l...
Recently read << >> java virtual machine-depth understanding of this book, for this part of the garbage collection algorithm to be finishing next notes. java runtime data area follows, in ...
GC algorithm Memory garbage collection focuses on java heap and method area. Objects survival judge Determining whether an object has survived there are two ways: Reference count: Each object has a re...
4 algorithms of GC Replication algorithm Let's first look at a schematic Clear scope Adopted in the young generationMinor GC The replication algorithm used by this GC algorithm Process analysis When t...
1. The concept of GC 2.GC algorithm 1… reference counting method 2… Mark removal method 3… Mark compression method 4 ... Copy algorithm 5 ... Generational thinking 3. Accessibilit...
(1) Reference counting method Explanation:Each object has a reference counter. When other declared variables point to this object, the counter will be +1, and when the point is gone, the counter will ...
What is GC Generational collection algorithm Frequently collected Yong area: Minor GC Old area is collected less frequently: Full GC Perm area which is basically stationary (1.8 is replaced by meta sp...
Preface GC garbage collection has a medium algorithm, mark copy Mark clear Mark compression Each algorithm has its own advantages and disadvantages. JVM garbage collection uses a generational algorith...
Basic term 1. Garbage This is the object that needs to be recycled. As the person who writes the program, it is possible to make the judgment "this object is no longer needed", but the compu...
GC Action area: When the JVM performs GC, it does not uniformly recycle these three areas. Most of the time, recycling is the new generation Cenozoic Survival area (form, to) elderly area Two types of...