@@ -219,17 +219,17 @@ they started originally) and setting its ``gc_refs`` field to 1. This is what ha
219
219
to ``link_2 `` and ``link_3 `` below as they are reachable from ``link_1 ``. From the
220
220
state in the previous image and after examining the objects referred to by ``link_1 ``
221
221
the GC knows that ``link_3 `` is reachable after all, so it is moved back to the
222
- original list and its ``gc_refs `` field is set to one so if the GC visits it again, it
223
- does know that is reachable. To avoid visiting a object twice, the GC marks all
224
- objects that are already visited once (by unsetting the ``PREV_MASK_COLLECTING `` flag)
225
- so if an object that has already been processed is referred by some other object, the
226
- GC does not process it twice.
222
+ original list and its ``gc_refs `` field is set to 1 so that if the GC visits it again,
223
+ it will know that it's reachable. To avoid visiting an object twice, the GC marks all
224
+ objects that have already been visited once (by unsetting the ``PREV_MASK_COLLECTING ``
225
+ flag) so that if an object that has already been processed is referenced by some other
226
+ object, the GC does not process it twice.
227
227
228
228
.. figure :: images/python-cyclic-gc-5-new-page.png
229
229
230
- Notice that once an object that was marked as "tentatively unreachable" and later is
231
- moved back to the reachable list, it will be visited again by the garbage collector
232
- as now all the references that that objects has need to be processed as well. This
230
+ Notice that an object that was marked as "tentatively unreachable" and was later
231
+ moved back to the reachable list will be visited again by the garbage collector
232
+ as now all the references that that object has need to be processed as well. This
233
233
process is really a breadth first search over the object graph. Once all the objects
234
234
are scanned, the GC knows that all container objects in the tentatively unreachable
235
235
list are really unreachable and can thus be garbage collected.
@@ -276,7 +276,7 @@ follows these steps in order:
276
276
set is going to be destroyed and has weak references with callbacks, these
277
277
callbacks need to be honored. This process is **very ** delicate as any error can
278
278
cause objects that will be in an inconsistent state to be resurrected or reached
279
- by some python functions invoked from the callbacks. In addition, weak references
279
+ by some Python functions invoked from the callbacks. In addition, weak references
280
280
that also are part of the unreachable set (the object and its weak reference
281
281
are in cycles that are unreachable) need to be cleaned
282
282
8000
immediately, without executing the callback. Otherwise it will be triggered later,
@@ -304,9 +304,9 @@ optimization: generations. The main idea behind this concept is the assumption t
304
304
most objects have a very short lifespan and can thus be collected shortly after their
305
305
creation. This has proven to be very close to the reality of many Python programs as
306
306
many temporarily objects are created and destroyed very fast. The older an object is
307
- the less likely it is to become unreachable.
307
+ the less likely it is that it will become unreachable.
308
308
309
- To take advantage of this fact, all container objects are segregated across
309
+ To take advantage of this fact, all container objects are segregated into
310
310
three spaces/generations. Every new
311
311
object starts in the first generation (generation 0). The previous algorithm is
312
312
executed only over the objects of a particular generation and if an object
@@ -316,7 +316,7 @@ the same object survives another GC round in this new generation (generation 1)
316
316
it will be moved to the last generation (generation 2) where it will be
317
317
surveyed the least often.
318
318
319
- Generations are collected when the number of objects that they contain reach some
319
+ Generations are collected when the number of objects that they contain reaches some
320
320
predefined threshold, which is unique for each generation and is lower the older
321
321
the generations are. These thresholds can be examined using the ``gc.get_threshold ``
322
322
function:
@@ -402,10 +402,10 @@ bit a separate tag) – as long as code that uses the pointer masks out these
402
402
bits before accessing memory. E.g., on a 32-bit architecture (for both
403
403
addresses and word size), a word is 32 bits = 4 bytes, so word-aligned
404
404
addresses are always a multiple of 4, hence end in ``00 ``, leaving the last 2 bits
405
- available; while on a 64-bit architecture, a word is 64 bits word = 8 bytes, so
405
+ available; while on a 64-bit architecture, a word is 64 bits = 8 bytes, so
406
406
word-aligned addresses end in ``000 ``, leaving the last 3 bits available.
407
407
408
- The CPython GC makes use of two fat pointers that corresponds to the extra fields
408
+ The CPython GC makes use of two fat pointers that correspond to the extra fields
409
409
of ``PyGC_Head `` discussed in the `Memory layout and object structure `_ section:
410
410
411
411
.. warning ::
@@ -440,7 +440,7 @@ Optimization: delay tracking containers
440
440
441
441
Certain types of containers cannot participate in a reference cycle, and so do
442
442
not need to be tracked by the garbage collector. Untracking these objects
443
- reduces the cost of garbage collections . However, determining which objects may
443
+ reduces the cost of garbage collection . However, determining which objects may
444
444
be untracked is not free, and the costs must be weighed against the benefits
445
445
for garbage collection. There are two possible strategies for when to untrack
446
446
a container:
<
635A
/div>
@@ -470,7 +470,7 @@ benefit from delayed tracking:
470
470
full garbage collection (all generations), the collector will untrack any dictionaries
471
471
whose contents are not tracked.
472
472
473
- The garbage collector module provides the python function is_tracked(obj), which returns
473
+ The garbage collector module provides the Python function `` is_tracked(obj) `` , which returns
474
474
the current tracking status of the object. Subsequent garbage collections may change the
475
475
tracking status of the object.
476
476
0 commit comments