What is GC?
Generational collection algorithm
1) Minor GC: Young area is collected frequently in number of times
2) Full GC: Old area is collected less frequently
3) Basically do not move the Perm area
GC occurs in the heap
GC algorithm
1) Reference counting method (has been deprecated)
2) Copying algorithm (Copying)
Occurs in the young generation , using Minor GC
principle:
Starting from the root set (GC Root), through Tracing from
Find the surviving object in From and copy it to To
From and To exchange identities, the next memory allocation starts from To
advantage:
1) No marking and removal process, high efficiency
2) There is no memory fragmentation , you can use bump-the-pointer to achieve fast memory allocation
Disadvantages:
Need double space
3) Mark-Sweep
Happened in the old age
标记
: Start scanning from the root collection and mark the surviving objects
清除
: Scan the entire memory space, reclaim unmarked objects, use free-list to record the available areas
advantage
No extra space required
Disadvantage
1) Two scans are time-consuming
2) Memory fragmentation will occur
4) Mark-Compact
Happened in the old age
principle
1) Mark: Same as mark-clear
2) Compression: Scan twice and slide the surviving object to one end
advantage
No memory fragmentation
Disadvantage
The cost of moving objects
5) Mark-Sweep-Compact
Actually 3) and 4) are used in combination