@@ -92,7 +92,7 @@ As is explained later in the `Optimization: reusing fields to save memory`_ sect
92
92
these two extra fields are normally used to keep doubly linked lists of all the
93
93
objects tracked by the garbage collector (these lists are the GC generations, more on
94
94
that in the `Optimization: generations `_ section), but they are also
95
- reused to fullfill other purposes when the full doubly linked list structure is not
95
+ reused to fulfill other purposes when the full doubly linked list structure is not
96
96
needed as a memory optimization.
97
97
98
98
Doubly linked lists are used because they efficiently support most frequently required operations. In
@@ -117,7 +117,7 @@ that the objects cannot form reference cycles with only objects of its type or u
117
117
the type is immutable, a ``tp_clear `` implementation must also be provided.
118
118
119
119
120
- Identifiying reference cycles
120
+ Identifying reference cycles
121
121
----------------------------------------------
122
122
123
123
The algorithm that CPython uses to detect those reference cycles is
@@ -164,7 +164,9 @@ is completely unreachable:
164
164
165
165
>> > link_4 = Link()
166
166
>> > link_4.next_link = link_4
167
+ >> > del link_4
167
168
169
+ # Collect the unreachable Link object (and its .__dict__ dict).
168
170
>> > gc.collect()
169
171
2
170
172
@@ -285,7 +287,7 @@ follows these steps in order:
285
287
2. If an object has legacy finalizers (``tp_del `` slot) move them to the
286
288
``gc.garbage `` list.
287
289
3. Call the finalizers (``tp_finalize `` slot) and mark the objects as already
288
- finalized to avoid calling them twice if they resurrect of if other finalizers
290
+ finalized to avoid calling them twice if they resurrect or if other finalizers
289
291
have removed the object first.
290
292
4. Deal with resurrected objects. If some objects have been resurrected, the GC
291
293
finds the new subset of objects that are still unreachable by running the cycle
@@ -337,23 +339,23 @@ specifically in a generation by calling ``gc.collect(generation=NUM)``.
337
339
... pass
338
340
...
339
341
340
- # Move everything to the last generation so its easier to inspect
342
+ # Move everything to the last generation so it's easier to inspect
341
343
# the younger generations.
342
344
343
345
>> > gc.collect()
344
346
0
345
347
346
- # Create a reference cycle
348
+ # Create a reference cycle.
347
349
348
350
>> > x = MyObj()
349
351
>> > x.self = x
350
352
351
- # Initially the object is in the younguest generation.
353
+ # Initially the object is in the youngest generation.
352
354
353
355
>> > gc.get_objects(generation = 0 )
354
356
[... , < __main__.MyObj object at 0x 7fbcc12a3400> , ... ]
355
357
356
- # After a collection of the younguest generation the object
358
+ # After a collection of the youngest generation the object
357
359
# moves to the next generation.
358
360
359
361
>> > gc.collect(generation = 0 )
0 commit comments