Skip to content

Commit 7637f36

Browse files
Deploy preview for PR 1226 🛫
1 parent 565342d commit 7637f36

582 files changed

Lines changed: 640 additions & 625 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pr-preview/pr-1226/_sources/library/gc.rst.txt

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

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

43-
Perform a collection. The optional argument *generation*
43+
With no arguments, run a full collection. The optional argument *generation*
4444
may be an integer specifying which generation to collect (from 0 to 2). A
4545
: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-
5548
The free lists maintained for a number of built-in types are cleared
5649
whenever a full collection or collection of the highest generation (2)
5750
is run. Not all items in some free lists may be freed due to the
@@ -63,6 +56,9 @@ The :mod:`!gc` module provides the following functions:
6356
.. versionchanged:: 3.14
6457
``generation=1`` performs an increment of collection.
6558

59+
.. versionchanged:: 3.14.5
60+
``generation=1`` performs collection of the middle generation.
61+
6662

6763
.. function:: set_debug(flags)
6864

@@ -78,20 +74,19 @@ The :mod:`!gc` module provides the following functions:
7874

7975
.. function:: get_objects(generation=None)
8076

81-
8277
Returns a list of all objects tracked by the collector, excluding the list
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.14)
87-
* 2: All objects in the old generation
78+
returned. If *generation* is not ``None``, return only the objects tracked by
79+
the collector that are in that generation.
8880

8981
.. versionchanged:: 3.8
9082
New *generation* parameter.
9183

9284
.. versionchanged:: 3.14
9385
Generation 1 is removed
9486

87+
.. versionchanged:: 3.14.5
88+
Generation 1 is reintroduced to maintain GC behavior from 3.13.
89+
9590
.. audit-event:: gc.get_objects generation gc.get_objects
9691

9792
.. function:: get_stats()
@@ -118,33 +113,33 @@ The :mod:`!gc` module provides the following functions:
118113
Set the garbage collection thresholds (the collection frequency). Setting
119114
*threshold0* to zero disables collection.
120115

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
116+
The GC classifies objects into three generations depending on how many
117+
collection sweeps they have survived. New objects are placed in the youngest
118+
generation (generation ``0``). If an object survives a collection it is moved
119+
into the next older generation. Since generation ``2`` is the oldest
120+
generation, objects in that generation remain there after a collection. In
121+
order to decide when to run, the collector keeps track of the number object
126122
allocations and deallocations since the last collection. When the number of
127123
allocations minus the number of deallocations exceeds *threshold0*, collection
128-
starts. For each collection, all the objects in the young generation and some
129-
fraction of the old generation is collected.
124+
starts. Initially only generation ``0`` is examined. If generation ``0`` has
125+
been examined more than *threshold1* times since generation ``1`` has been
126+
examined, then generation ``1`` is examined as well.
127+
With the third generation, things are a bit more complicated,
128+
see `Collecting the oldest generation <https://github.com/python/cpython/blob/ff0ef0a54bef26fc507fbf9b7a6009eb7d3f17f5/InternalDocs/garbage_collector.md#collecting-the-oldest-generation>`_ for more information.
130129

131130
In the free-threaded build, the increase in process memory usage is also
132131
checked before running the collector. If the memory usage has not increased
133132
by 10% since the last collection and the net number of object allocations
134133
has not exceeded 40 times *threshold0*, the collection is not run.
135134

136-
The fraction of the old generation that is collected is **inversely** proportional
137-
to *threshold1*. The larger *threshold1* is, the slower objects in the old generation
138-
are collected.
139-
For the default value of 10, 1% of the old generation is scanned during each collection.
140-
141-
*threshold2* is ignored.
142-
143135
See `Garbage collector design <https://github.com/python/cpython/blob/3.14/InternalDocs/garbage_collector.md>`_ for more information.
144136

145137
.. versionchanged:: 3.14
146138
*threshold2* is ignored
147139

140+
.. versionchanged:: 3.14.5
141+
*threshold2* is restored to match Python 3.13 behavior.
142+
148143

149144
.. function:: get_count()
150145

pr-preview/pr-1226/about.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ <h3>導航</h3>
356356
<a href="https://www.python.org/psf/donations/">敬請捐贈。</a>
357357
<br>
358358
<br>
359-
最後更新於 4月 26, 2026 (04:09 UTC)。
359+
最後更新於 4月 27, 2026 (00:34 UTC)。
360360

361361
<a href="/bugs.html">發現 bug</a>
362362

pr-preview/pr-1226/bugs.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ <h2>說明文件的錯誤<a class="headerlink" href="#documentation-bugs" title=
250250
</section>
251251
<section id="getting-started-contributing-to-python-yourself">
252252
<span id="contributing-to-python"></span><h2>開始讓自己貢獻 Python<a class="headerlink" href="#getting-started-contributing-to-python-yourself" title="連結到這個標頭"></a></h2>
253-
<p>除了只是回報你所發現的錯誤之外,同樣也歡迎你提交修正它們的修補程式 (patch)。你可以在 <a class="reference external" href="https://devguide.python.org/">Python 開發者指南</a>中找到如何開始修補 Python 的更多資訊。如果你有任何問題,<a class="reference external" href="https://mail.python.org/mailman3/lists/core-mentorship.python.org/">核心導師郵寄清單</a>是一個友善的地方,你可以在那裡得到,關於 Python 修正錯誤的過程中,所有問題的答案。</p>
253+
<p>除了只是回報你所發現的錯誤之外,同樣也歡迎你提交修正它們的修補程式 (patch)。你可以在 <a class="reference external" href="https://mail.python.org/mailman3/lists/core-mentorship.python.org/">Python 開發者指南</a>中找到如何開始修補 Python 的更多資訊。如果你有任何問題,<a class="reference external" href="https://devguide.python.org/">核心導師郵寄清單</a>是一個友善的地方,你可以在那裡得到,關於 Python 修正錯誤的過程中,所有問題的答案。</p>
254254
</section>
255255
</section>
256256

@@ -393,7 +393,7 @@ <h3>導航</h3>
393393
<a href="https://www.python.org/psf/donations/">敬請捐贈。</a>
394394
<br>
395395
<br>
396-
最後更新於 4月 26, 2026 (04:09 UTC)。
396+
最後更新於 4月 27, 2026 (00:34 UTC)。
397397

398398
<a href="/bugs.html">發現 bug</a>
399399

pr-preview/pr-1226/c-api/abstract.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ <h3>導航</h3>
365365
<a href="https://www.python.org/psf/donations/">敬請捐贈。</a>
366366
<br>
367367
<br>
368-
最後更新於 4月 26, 2026 (04:09 UTC)。
368+
最後更新於 4月 27, 2026 (00:34 UTC)。
369369

370370
<a href="/bugs.html">發現 bug</a>
371371

pr-preview/pr-1226/c-api/allocation.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ <h3>導航</h3>
577577
<a href="https://www.python.org/psf/donations/">敬請捐贈。</a>
578578
<br>
579579
<br>
580-
最後更新於 4月 26, 2026 (04:09 UTC)。
580+
最後更新於 4月 27, 2026 (00:34 UTC)。
581581

582582
<a href="/bugs.html">發現 bug</a>
583583

pr-preview/pr-1226/c-api/apiabiversion.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ <h3>導航</h3>
514514
<a href="https://www.python.org/psf/donations/">敬請捐贈。</a>
515515
<br>
516516
<br>
517-
最後更新於 4月 26, 2026 (04:09 UTC)。
517+
最後更新於 4月 27, 2026 (00:34 UTC)。
518518

519519
<a href="/bugs.html">發現 bug</a>
520520

pr-preview/pr-1226/c-api/arg.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ <h3>導航</h3>
996996
<a href="https://www.python.org/psf/donations/">敬請捐贈。</a>
997997
<br>
998998
<br>
999-
最後更新於 4月 26, 2026 (04:09 UTC)。
999+
最後更新於 4月 27, 2026 (00:34 UTC)。
10001000

10011001
<a href="/bugs.html">發現 bug</a>
10021002

pr-preview/pr-1226/c-api/bool.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ <h3>導航</h3>
376376
<a href="https://www.python.org/psf/donations/">敬請捐贈。</a>
377377
<br>
378378
<br>
379-
最後更新於 4月 26, 2026 (04:09 UTC)。
379+
最後更新於 4月 27, 2026 (00:34 UTC)。
380380

381381
<a href="/bugs.html">發現 bug</a>
382382

pr-preview/pr-1226/c-api/buffer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ <h3>導航</h3>
10641064
<a href="https://www.python.org/psf/donations/">敬請捐贈。</a>
10651065
<br>
10661066
<br>
1067-
最後更新於 4月 26, 2026 (04:09 UTC)。
1067+
最後更新於 4月 27, 2026 (00:34 UTC)。
10681068

10691069
<a href="/bugs.html">發現 bug</a>
10701070

pr-preview/pr-1226/c-api/bytearray.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ <h3>導航</h3>
457457
<a href="https://www.python.org/psf/donations/">敬請捐贈。</a>
458458
<br>
459459
<br>
460-
最後更新於 4月 26, 2026 (04:09 UTC)。
460+
最後更新於 4月 27, 2026 (00:34 UTC)。
461461

462462
<a href="/bugs.html">發現 bug</a>
463463

0 commit comments

Comments
 (0)