mirror of
https://github.com/python/cpython.git
synced 2025-10-03 05:35:59 +00:00
[3.11] gh-103059: Clarify gc.freeze documentation (GH-103058) (#103416)
gh-103059: Clarify gc.freeze documentation (GH-103058)
(cherry picked from commit 8b1b17134e
)
Co-authored-by: raylu <lurayl@gmail.com>
This commit is contained in:
parent
0f6319fc8c
commit
b80e4c89d8
2 changed files with 12 additions and 6 deletions
|
@ -206,12 +206,17 @@ The :mod:`gc` module provides the following functions:
|
||||||
|
|
||||||
.. function:: freeze()
|
.. function:: freeze()
|
||||||
|
|
||||||
Freeze all the objects tracked by gc - move them to a permanent generation
|
Freeze all the objects tracked by the garbage collector; move them to a
|
||||||
and ignore all the future collections. This can be used before a POSIX
|
permanent generation and ignore them in all the future collections.
|
||||||
fork() call to make the gc copy-on-write friendly or to speed up collection.
|
|
||||||
Also collection before a POSIX fork() call may free pages for future
|
If a process will ``fork()`` without ``exec()``, avoiding unnecessary
|
||||||
allocation which can cause copy-on-write too so it's advised to disable gc
|
copy-on-write in child processes will maximize memory sharing and reduce
|
||||||
in parent process and freeze before fork and enable gc in child process.
|
overall memory usage. This requires both avoiding creation of freed "holes"
|
||||||
|
in memory pages in the parent process and ensuring that GC collections in
|
||||||
|
child processes won't touch the ``gc_refs`` counter of long-lived objects
|
||||||
|
originating in the parent process. To accomplish both, call ``gc.disable()``
|
||||||
|
early in the parent process, ``gc.freeze()`` right before ``fork()``, and
|
||||||
|
``gc.enable()`` early in child processes.
|
||||||
|
|
||||||
.. versionadded:: 3.7
|
.. versionadded:: 3.7
|
||||||
|
|
||||||
|
|
|
@ -1103,6 +1103,7 @@ Jason Lowe
|
||||||
Tony Lownds
|
Tony Lownds
|
||||||
Ray Loyzaga
|
Ray Loyzaga
|
||||||
Kang-Hao (Kenny) Lu
|
Kang-Hao (Kenny) Lu
|
||||||
|
Raymond Lu
|
||||||
Lukas Lueg
|
Lukas Lueg
|
||||||
Loren Luke
|
Loren Luke
|
||||||
Fredrik Lundh
|
Fredrik Lundh
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue