Skip to content

Commit 45df217

Browse files
Merge branch 'main' into ssl-bugfix-116810
2 parents c66f537 + 08c0166 commit 45df217

21 files changed

+635
-366
lines changed

Doc/glossary.rst

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -590,14 +590,12 @@ Glossary
590590
which ships with the standard distribution of Python.
591591

592592
immortal
593-
If an object is immortal, its reference count is never modified, and
594-
therefore it is never deallocated.
593+
*Immortal objects* are a CPython implementation detail introduced
594+
in :pep:`683`.
595595

596-
Built-in strings and singletons are immortal objects. For example,
597-
:const:`True` and :const:`None` singletons are immortal.
598-
599-
See `PEP 683 – Immortal Objects, Using a Fixed Refcount
600-
<https://peps.python.org/pep-0683/>`_ for more information.
596+
If an object is immortal, its :term:`reference count` is never modified,
597+
and therefore it is never deallocated while the interpreter is running.
598+
For example, :const:`True` and :const:`None` are immortal in CPython.
601599

602600
immutable
603601
An object with a fixed value. Immutable objects include numbers, strings and

Doc/library/gc.rst

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,18 @@ The :mod:`gc` module provides the following functions:
4040

4141
.. function:: collect(generation=2)
4242

43-
With no arguments, run a full collection. The optional argument *generation*
43+
Perform a collection. The optional argument *generation*
4444
may be an integer specifying which generation to collect (from 0 to 2). A
45-
:exc:`ValueError` is raised if the generation number is invalid. The sum of
45+
:exc:`ValueError` is raised if the generation number is invalid. The sum of
4646
collected objects and uncollectable objects is returned.
4747

48+
Calling ``gc.collect(0)`` will perform a GC collection on the young generation.
49+
50+
Calling ``gc.collect(1)`` will perform a GC collection on the young generation
51+
and an increment of the old generation.
52+
53+
Calling ``gc.collect(2)`` or ``gc.collect()`` performs a full collection
54+
4855
The free lists maintained for a number of built-in types are cleared
4956
whenever a full collection or collection of the highest generation (2)
5057
is run. Not all items in some free lists may be freed due to the
@@ -53,6 +60,9 @@ The :mod:`gc` module provides the following functions:
5360
The effect of calling ``gc.collect()`` while the interpreter is already
5461
performing a collection is undefined.
5562

63+
.. versionchanged:: 3.13
64+
``generation=1`` performs an increment of collection.
65+
5666

5767
.. function:: set_debug(flags)
5868

@@ -68,13 +78,20 @@ The :mod:`gc` module provides the following functions:
6878

6979
.. function:: get_objects(generation=None)
7080

81+
7182
Returns a list of all objects tracked by the collector, excluding the list
72-
returned. If *generation* is not ``None``, return only the objects tracked by
73-
the collector that are in that generation.
83+
returned. If *generation* is not ``None``, return only the objects as follows:
84+
85+
* 0: All objects in the young generation
86+
* 1: No objects, as there is no generation 1 (as of Python 3.13)
87+
* 2: All objects in the old generation
7488

7589
.. versionchanged:: 3.8
7690
New *generation* parameter.
7791

92+
.. versionchanged:: 3.13
93+
Generation 1 is removed
94+
7895
.. audit-event:: gc.get_objects generation gc.get_objects
7996

8097
.. function:: get_stats()
@@ -101,19 +118,27 @@ The :mod:`gc` module provides the following functions:
101118
Set the garbage collection thresholds (the collection frequency). Setting
102119
*threshold0* to zero disables collection.
103120

104-
The GC classifies objects into three generations depending on how many
105-
collection sweeps they have survived. New objects are placed in the youngest
106-
generation (generation ``0``). If an object survives a collection it is moved
107-
into the next older generation. Since generation ``2`` is the oldest
108-
generation, objects in that generation remain there after a collection. In
109-
order to decide when to run, the collector keeps track of the number object
121+
The GC classifies objects into two generations depending on whether they have
122+
survived a collection. New objects are placed in the young generation. If an
123+
object survives a collection it is moved into the old generation.
124+
125+
In order to decide when to run, the collector keeps track of the number of object
110126
allocations and deallocations since the last collection. When the number of
111127
allocations minus the number of deallocations exceeds *threshold0*, collection
112-
starts. Initially only generation ``0`` is examined. If generation ``0`` has
113-
been examined more than *threshold1* times since generation ``1`` has been
114-
examined, then generation ``1`` is examined as well.
115-
With the third generation, things are a bit more complicated,
116-
see `Collecting the oldest generation <https://devguide.python.org/garbage_collector/#collecting-the-oldest-generation>`_ for more information.
128+
starts. For each collection, all the objects in the young generation and some
129+
fraction of the old generation is collected.
130+
131+
The fraction of the old generation that is collected is **inversely** proportional
132+
to *threshold1*. The larger *threshold1* is, the slower objects in the old generation
133+
are collected.
134+
For the default value of 10, 1% of the old generation is scanned during each collection.
135+
136+
*threshold2* is ignored.
137+
138+
See `Garbage collector design <https://devguide.python.org/garbage_collector>`_ for more information.
139+
140+
.. versionchanged:: 3.13
141+
*threshold2* is ignored
117142

118143

119144
.. function:: get_count()

Doc/whatsnew/3.13.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,19 @@ Incremental garbage collection
495495
The cycle garbage collector is now incremental.
496496
This means that maximum pause times are reduced
497497
by an order of magnitude or more for larger heaps.
498+
499+
There are now only two generations: young and old.
500+
When :func:`gc.collect` is not called directly, the
501+
GC is invoked a little less frequently. When invoked, it
502+
collects the young generation and an increment of the
503+
old generation, instead of collecting one or more generations.
504+
505+
The behavior of :func:`!gc.collect` changes slightly:
506+
507+
* ``gc.collect(1)``: Performs an increment of GC,
508+
rather than collecting generation 1.
509+
* Other calls to :func:`!gc.collect` are unchanged.
510+
498511
(Contributed by Mark Shannon in :gh:`108362`.)
499512

500513

@@ -1480,7 +1493,7 @@ Optimizations
14801493
Other modules to enjoy import-time speedups include
14811494
:mod:`email.utils`, :mod:`enum`, :mod:`functools`,
14821495
:mod:`importlib.metadata`, and :mod:`threading`.
1483-
(Contributed by Alex Waygood, Shantanu Jain, Adam Turner, Daniel Holla,
1496+
(Contributed by Alex Waygood, Shantanu Jain, Adam Turner, Daniel Hollas,
14841497
and others in :gh:`109653`.)
14851498

14861499
* :func:`textwrap.indent` is now around 30% faster than before for large input.

Include/internal/pycore_dict.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ typedef struct {
8383
PyObject *me_value; /* This field is only meaningful for combined tables */
8484
} PyDictUnicodeEntry;
8585

86-
extern PyDictKeysObject *_PyDict_NewKeysForClass(void);
86+
extern PyDictKeysObject *_PyDict_NewKeysForClass(PyHeapTypeObject *);
8787
extern PyObject *_PyDict_FromKeys(PyObject *, PyObject *, PyObject *);
8888

8989
/* Gets a version number unique to the current state of the keys of dict, if possible.

0 commit comments

Comments
 (0)