Skip to content

Commit fc6b1d8

Browse files
nanjekyejoannahpablogsal
authored andcommitted
Editorial fixes to garbage_collector.rst (#564)
1 parent 373762d commit fc6b1d8

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

garbage_collector.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Design of CPython's Garbage Collector
1010
Abstract
1111
--------
1212

13-
The main garbage collector system of CPython is reference count. The basic idea is
13+
The main garbage collection algorithm used by CPython is reference counting. The basic idea is
1414
that CPython counts how many different places there are that have a reference to an
1515
object. Such a place could be another object, or a global (or static) C variable, or
1616
a local variable in some C function. When an object’s reference count becomes zero,
@@ -33,8 +33,8 @@ to the object when called):
3333
>>> sys.getrefcount(x)
3434
2
3535
36-
The main problem with the reference count schema is that reference counting
37-
does not handle reference cycles. For instance, consider this code:
36+
The main problem with the reference counting scheme is that it does not handle reference
37+
cycles. For instance, consider this code:
3838

3939
.. code-block:: python
4040
@@ -98,7 +98,7 @@ needed as a memory optimization.
9898
Doubly linked lists are used because they efficiently support most frequently required operations. In
9999
general, the collection of all objects tracked by GC are partitioned into disjoint sets, each in its own
100100
doubly linked list. Between collections, objects are partitioned into "generations", reflecting how
101-
often they've survived collection attempts. During collections, the generations(s) being collected
101+
often they've survived collection attempts. During collections, the generation(s) being collected
102102
are further partitioned into, e.g., sets of reachable and unreachable objects. Doubly linked lists
103103
support moving an object from one partition to another, adding a new object, removing an object
104104
entirely (objects tracked by GC are most often reclaimed by the refcounting system when GC
@@ -204,7 +204,7 @@ processed ``link_1`` and ``link_2`` yet.
204204

205205
.. figure:: images/python-cyclic-gc-3-new-page.png
206206

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

@@ -225,7 +225,7 @@ GC does not process it twice.
225225

226226
.. figure:: images/python-cyclic-gc-5-new-page.png
227227

228-
Notice that once a object that was marked as "tentatively unreachable" and later is
228+
Notice that once an object that was marked as "tentatively unreachable" and later is
229229
moved back to the reachable list, it will be visited again by the garbage collector
230230
as now all the references that that objects has need to be processed as well. This
231231
process is really a breadth first search over the object graph. Once all the objects
@@ -276,7 +276,7 @@ follows these steps in order:
276276
cause objects that will be in an inconsistent state to be resurrected or reached
277277
by some python functions invoked from the callbacks. In addition, weak references
278278
that also are part of the unreachable set (the object and its weak reference
279-
are in a cycles that are unreachable) need to be cleaned
279+
are in cycles that are unreachable) need to be cleaned
280280
immediately, without executing the callback. Otherwise it will be triggered later,
281281
when the ``tp_clear`` slot is called, causing havoc. Ignoring the weak reference's
282282
callback is fine because both the object and the weakref are going away, so it's
@@ -287,7 +287,7 @@ follows these steps in order:
287287
3. Call the finalizers (``tp_finalize`` slot) and mark the objects as already
288288
finalized to avoid calling them twice if they resurrect of if other finalizers
289289
have removed the object first.
290-
4. Deal with resurrected objects. If some objects have been resurrected the GC
290+
4. Deal with resurrected objects. If some objects have been resurrected, the GC
291291
finds the new subset of objects that are still unreachable by running the cycle
292292
detection algorithm again and continues with them.
293293
5. Call the ``tp_clear`` slot of every object so all internal links are broken and
@@ -316,7 +316,7 @@ surveyed the least often.
316316

317317
Generations are collected when the number of objects that they contain reach some
318318
predefined threshold, which is unique for each generation and is lower the older
319-
generations are. These thresholds can be examined using the ``gc.get_threshold``
319+
the generations are. These thresholds can be examined using the ``gc.get_threshold``
320320
function:
321321

322322
.. code-block:: python

0 commit comments

Comments
 (0)