Let's learn the garbage collection mechanism first -> GC
Generally occurs in the JVM heap,
Minor GC is frequently collected in the young area (young generation)
In the old area (old generation) less Full GC is collected
perm permanent area without GC
Four algorithms
1. Reference counting method (this algorithm has been eliminated, just know it)
As long as an object is referenced, it will not be recycled, and it will not be processed in circular references;
2. Copy algorithm
Copy from one area of one memory to another,
The advantages are high efficiency, no memory fragmentation, and continuous copying of the past.
The disadvantage is that it needs double the memory space,
Acting in the young area (young generation)
3. Sign clear
Mark first and then clear, clear the unmarked (survivors),
Disadvantages: two scans, one mark and one clear. If there is no mark as shown in the figure, it will be vacant, which is memory fragmentation;
Advantages: No extra space is required, and it is designed for this memory operation;
Acting on the old area (old age)
4 logo compression
Mark first and then compress, move the discontinuous ones to become continuous
Disadvantages: two scans; cost of moving objects
Advantages: no need for additional space, no memory fragmentation
Acting on the old area (old age)
5. Logo clear compression (combined 4\5)
Reduce the cost of moving objects ()
summary:
1. Where does GC occur in the JVM? Answer: GC happened on the heap,
2. How many kinds of GC are there? Answer: There are two types of GC: minor GC, Full GC
3. How many algorithms are there? Answer: 5 kinds, one kind is eliminated, 4 kinds are left,
Minor GC occurs in the young area, using a copy algorithm
Full GC occurs in the old area and is processed by a combination of flag removal and flag compression. --These three algorithms are all marked, just remember