Skip to content

Commit 9513ac8

Browse files
authored
Use consistently 'gc_ref' in the garbage collector docs (#1029)
1 parent 863f854 commit 9513ac8

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

internals/garbage-collector.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,38 +191,38 @@ The GC then iterates over all containers in the first list and decrements by one
191191
this makes use of the ``tp_traverse`` slot in the container class (implemented
192192
using the C API or inherited by a superclass) to know what objects are referenced by
193193
each container. After all the objects have been scanned, only the objects that have
194-
references from outside the “objects to scan” list will have ``gc_refs > 0``.
194+
references from outside the “objects to scan” list will have ``gc_ref > 0``.
195195

196196
.. figure:: /_static/python-cyclic-gc-2-new-page.png
197197

198-
Notice that having ``gc_refs == 0`` does not imply that the object is unreachable.
199-
This is because another object that is reachable from the outside (``gc_refs > 0``)
198+
Notice that having ``gc_ref == 0`` does not imply that the object is unreachable.
199+
This is because another object that is reachable from the outside (``gc_ref > 0``)
200200
can still have references to it. For instance, the ``link_2`` object in our example
201-
ended having ``gc_refs == 0`` but is referenced still by the ``link_1`` object that
201+
ended having ``gc_ref == 0`` but is referenced still by the ``link_1`` object that
202202
is reachable from the outside. To obtain the set of objects that are really
203203
unreachable, the garbage collector re-scans the container objects using the
204204
``tp_traverse`` slot; this time with a different traverse function that marks objects with
205-
``gc_refs == 0`` as "tentatively unreachable" and then moves them to the
205+
``gc_ref == 0`` as "tentatively unreachable" and then moves them to the
206206
tentatively unreachable list. The following image depicts the state of the lists in a
207207
moment when the GC processed the ``link_3`` and ``link_4`` objects but has not
208208
processed ``link_1`` and ``link_2`` yet.
209209

210210
.. figure:: /_static/python-cyclic-gc-3-new-page.png
211211

212-
Then the GC scans the next ``link_1`` object. Because it has ``gc_refs == 1``,
212+
Then the GC scans the next ``link_1`` object. Because it has ``gc_ref == 1``,
213213
the gc does not do anything special because it knows it has to be reachable (and is
214214
already in what will become the reachable list):
215215

216216
.. figure:: /_static/python-cyclic-gc-4-new-page.png
217217

218-
When the GC encounters an object which is reachable (``gc_refs > 0``), it traverses
218+
When the GC encounters an object which is reachable (``gc_ref > 0``), it traverses
219219
its references using the ``tp_traverse`` slot to find all the objects that are
220220
reachable from it, moving them to the end of the list of reachable objects (where
221-
they started originally) and setting its ``gc_refs`` field to 1. This is what happens
221+
they started originally) and setting its ``gc_ref`` field to 1. This is what happens
222222
to ``link_2`` and ``link_3`` below as they are reachable from ``link_1``. From the
223223
state in the previous image and after examining the objects referred to by ``link_1``
224224
the GC knows that ``link_3`` is reachable after all, so it is moved back to the
225-
original list and its ``gc_refs`` field is set to 1 so that if the GC visits it again,
225+
original list and its ``gc_ref`` field is set to 1 so that if the GC visits it again,
226226
it will know that it's reachable. To avoid visiting an object twice, the GC marks all
227227
objects that have already been visited once (by unsetting the ``PREV_MASK_COLLECTING``
228228
flag) so that if an object that has already been processed is referenced by some other
@@ -431,7 +431,7 @@ of ``PyGC_Head`` discussed in the `Memory layout and object structure`_ section:
431431
``PREV_MASK_COLLECTING`` and ``_PyGC_PREV_MASK_FINALIZED``. Between collections,
432432
the only flag that can be present is ``_PyGC_PREV_MASK_FINALIZED`` that indicates
433433
if an object has been already finalized. During collections ``_gc_prev`` is
434-
temporarily used for storing a copy of the reference count (``gc_refs``), in
434+
temporarily used for storing a copy of the reference count (``gc_ref``), in
435435
addition to two flags, and the GC linked list becomes a singly linked list until
436436
``_gc_prev`` is restored.
437437

0 commit comments

Comments
 (0)