Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 376def3

Browse files
authored
Correct the description of generation thresholds in the gc docs (#1030)
1 parent 333df12 commit 376def3

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

internals/garbage-collector.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,15 @@ the same object survives another GC round in this new generation (generation 1)
319319
it will be moved to the last generation (generation 2) where it will be
320320
surveyed the least often.
321321

322-
Generations are collected when the number of objects that they contain reaches some
323-
predefined threshold, which is unique for each generation and is lower the older
324-
the generations are. These thresholds can be examined using the ``gc.get_threshold``
325-
function:
322+
In order to decide when to run, the collector keeps track of the number of object
323+
allocations and deallocations since the last collection. When the number of
324+
allocations minus the number of deallocations exceeds ``threshold_0``,
325+
collection starts. Initially only generation 0 is examined. If generation 0 has
326+
been examined more than ``threshold_1`` times since generation 1 has been
327+
examined, then generation 1 is examined as well. With generation 2,
328+
things are a bit more complicated; see :ref:`gc-oldest-generation` for
329+
more information. These thresholds can be examined using the
330+
:func:`gc.get_threshold` function:
326331

327332
.. code-block:: python
328333
@@ -369,6 +374,7 @@ specifically in a generation by calling ``gc.collect(generation=NUM)``.
369374
[..., <__main__.MyObj object at 0x7fbcc12a3400>, ...]
370375
371376
377+
.. _gc-oldest-generation:
372378

373379
Collecting the oldest generation
374380
--------------------------------

0 commit comments

Comments
 (0)