@@ -366,33 +366,39 @@ To take advantage of this fact, all container objects are segregated into
366366two generations: young and old. Every new object starts in the young generation.
367367In order to keep pause times down, scanning of the old generation of the heap
368368occurs in increments. To keep track of what has been scanned,
369- the old generation contains two lists: scanned and unscanned heap.
369+ the old generation contains two lists:
370+ 
371+ *  Those objects that have not yet been scanned, referred to as the ` pending `  list.
372+ *  Those objects that have been scanned, referred to as the ` visited `  list.
370373
371374To detect and collect all unreachable objects in the heap, the garbage collector
372375must scan the whole heap. This whole heap scan is called a full scavenge.
373376
374- To limit the time each garbage collection takes, the detection and collection
375- algorithm is executed only on a portion of the heap called an increment.
376- For each full scavenge, the increments will cover the whole heap.
377+ Increments
378+ ---------- 
379+ 
380+ Each full scavenge is performed in a series of increments.
381+ For each full scavenge, the combined increments will cover the whole heap.
377382
378- Each  increment, the portion of the heap scanned by a single collection is made up 
379- of three parts:
383+ For each  increment, the portion of the heap scanned by a single collection is
384+ made up  of three parts:
380385
381386*  The young generation
382- *  The old generation's least recently objects
387+ *  The old generation's least recently scanned  objects
383388*  All objects reachable from those objects that have not yet been scanned this full scavenge
384389
385- Any young generation objects surviving this collection are moved to the old generation,
386- and reachable objects in the old generation remain in the old generation.
387- The old generation is composed of two lists: scanned and unscanned.
388- (The implementation refers to the unscanned part as ` pending `  and the scanned part
389- as ` visited ` ).
390- Survivors are moved to the back of the scanned list. The old part of increment is taken
391- from the front of the unscanned list.
390+ The surviving objects (those that are not collected) are moved to the back of the
391+ ` visited `  list in the old generation.
392+ 
393+ When a full scavenge starts, no objects in the heap are considered to have been scanned,
394+ so all objects in the old generation must be in the ` pending `  space.
395+ When all objects in the heap have been scanned a cycle ends, and all objects are moved
396+ to the ` pending `  list again. To avoid having to traverse the entire list, which list is
397+ ` pending `  and which is ` visited `  is determined by a field in the ` GCState `  struct.
398+ The ` visited `  and ` pending `  lists can be swapped by toggling this bit.
392399
393- When a full scavenge starts, no objects in the heap are considered to have been scanned.
394- When all objects in the heap have been scanned a cycle ends, and all objects are
395- considered unscanned again.
400+ Correctness
401+ ----------- 
396402
397403In order to collect all unreachable cycles, each increment must contain all of
398404an unreachable cycle, or none of it.
@@ -404,7 +410,7 @@ Thus, to form a complete increment we perform a
404410over reachable, unscanned objects from the initial increment.
405411We can exclude scanned objects, as they must have been reachable when scanned.
406412If a scanned object becomes part of an unreachable cycle after being scanned, it
407- will not be collected this cycle, but it will be collected next full scavenge.
413+ will not be collected this cycle, but it will be collected in the  next full scavenge.
408414
409415>  [ !NOTE] 
410416>  The GC implementation for the free-threaded build does not use incremental collection.
@@ -417,7 +423,7 @@ collection starts. `threshold1` determines the fraction of the old
417423collection that is included in the increment.
418424The fraction is inversely proportional to ` threshold1 ` ,
419425as historically a larger ` threshold1 `  meant that old generation
420- collections were performed less frequency .
426+ collections were performed less frequently .
421427` threshold2 `  is ignored.
422428
423429These thresholds can be examined using the
@@ -441,7 +447,7 @@ specifically in a generation by calling `gc.collect(generation=NUM)`.
441447    ...
442448
443449    # Move everything to the old generation so it's easier to inspect
444-     # the young generations .
450+     # the young generation .
445451
446452    >>> gc.collect()
447453    0
0 commit comments