@@ -199,22 +199,22 @@ unreachable:
199199
200200``` pycon
201201>>> import gc
202- >>>
202+ >>>
203203>>> class Link :
204204... def __init__ (self , next_link = None ):
205205... self .next_link = next_link
206- ...
206+ ...
207207>>> link_3 = Link()
208208>>> link_2 = Link(link_3)
209209>>> link_1 = Link(link_2)
210210>>> link_3.next_link = link_1
211211>>> A = link_1
212212>>> del link_1, link_2, link_3
213- >>>
213+ >>>
214214>>> link_4 = Link()
215215>>> link_4.next_link = link_4
216216>>> del link_4
217- >>>
217+ >>>
218218>>> # Collect the unreachable Link object (and its .__dict__ dict).
219219>>> gc.collect()
2202202
@@ -278,7 +278,7 @@ state in the previous image and after examining the objects referred to by `link
278278the GC knows that ` link_3 ` is reachable after all, so it is moved back to the
279279original list and its ` gc_ref ` field is set to 1 so that if the GC visits it again,
280280it will know that it's reachable. To avoid visiting an object twice, the GC marks all
281- objects that have already been visited once (by unsetting the ` PREV_MASK_COLLECTING `
281+ objects that have already been visited once (by unsetting the ` _PyGC_PREV_MASK_COLLECTING `
282282flag) so that if an object that has already been processed is referenced by some other
283283object, the GC does not process it twice.
284284
@@ -465,11 +465,11 @@ specifically in a generation by calling `gc.collect(generation=NUM)`.
465465>>> # Create a reference cycle.
466466>>> x = MyObj()
467467>>> x.self = x
468- >>>
468+ >>>
469469>>> # Initially the object is in the young generation.
470470>>> gc.get_objects(generation = 0 )
471471[..., <__main__.MyObj object at 0x7fbcc12a3400>, ...]
472- >>>
472+ >>>
473473>>> # After a collection of the youngest generation the object
474474>>> # moves to the old generation.
475475>>> gc.collect(generation = 0 )
@@ -725,21 +725,27 @@ of `PyGC_Head` discussed in the `Memory layout and object structure`_ section:
725725
726726- The ` _gc_prev ` field is normally used as the "previous" pointer to maintain the
727727 doubly linked list but its lowest two bits are used to keep the flags
728- ` PREV_MASK_COLLECTING ` and ` _PyGC_PREV_MASK_FINALIZED ` . Between collections,
728+ ` _PyGC_PREV_MASK_COLLECTING ` and ` _PyGC_PREV_MASK_FINALIZED ` . Between collections,
729729 the only flag that can be present is ` _PyGC_PREV_MASK_FINALIZED ` that indicates
730730 if an object has been already finalized. During collections ` _gc_prev ` is
731731 temporarily used for storing a copy of the reference count (` gc_ref ` ), in
732732 addition to two flags, and the GC linked list becomes a singly linked list until
733733 ` _gc_prev ` is restored.
734734
735- - The ` _gc_next ` field is used as the "next" pointer to maintain the doubly linked
736- list but during collection its lowest bit is used to keep the
737- ` NEXT_MASK_UNREACHABLE ` flag that indicates if an object is tentatively
735+ - The ` _gc_next ` field is normally used as the "next" pointer to maintain the
736+ doubly linked list but its lowest two bits are used to keep the flags
737+ ` _PyGC_NEXT_MASK_OLD_SPACE_1 ` and ` _PyGC_NEXT_MASK_UNREACHABLE ` .
738+ During collection, the ` _PyGC_NEXT_MASK_UNREACHABLE ` flag indicates if an object is tentatively
738739 unreachable during the cycle detection algorithm. This is a drawback to using only
739740 doubly linked lists to implement partitions: while most needed operations are
740741 constant-time, there is no efficient way to determine which partition an object is
741742 currently in. Instead, when that's needed, ad hoc tricks (like the
742- ` NEXT_MASK_UNREACHABLE ` flag) are employed.
743+ ` _PyGC_NEXT_MASK_UNREACHABLE ` flag) are employed.
744+ The ` _PyGC_NEXT_MASK_OLD_SPACE_1 ` flag
745+ indicates whether the object belongs to the pending space or the
746+ visited space. The objects in the pending space are yet to be processed
747+ during future incremental collections. Which space is which is determined
748+ by gcstate->visited_space.
743749
744750Optimization: delayed untracking containers
745751===========================================
0 commit comments