diff options
author | raylu <lurayl@gmail.com> | 2023-04-10 16:30:32 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-10 16:30:32 (GMT) |
commit | 8b1b17134e2241a8cdff9e0c869013a7ff3ca2fe (patch) | |
tree | 91537f30c1730accb2695e822c3466ab05ef9789 /Doc/library/gc.rst | |
parent | 40db5c65b7ca4e784613b6122106a92576aba2d6 (diff) | |
download | cpython-8b1b17134e2241a8cdff9e0c869013a7ff3ca2fe.zip cpython-8b1b17134e2241a8cdff9e0c869013a7ff3ca2fe.tar.gz cpython-8b1b17134e2241a8cdff9e0c869013a7ff3ca2fe.tar.bz2 |
gh-103059: Clarify gc.freeze documentation (#103058)
Diffstat (limited to 'Doc/library/gc.rst')
-rw-r--r-- | Doc/library/gc.rst | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/Doc/library/gc.rst b/Doc/library/gc.rst index 832ebaf..6d5c64d 100644 --- a/Doc/library/gc.rst +++ b/Doc/library/gc.rst @@ -206,12 +206,17 @@ The :mod:`gc` module provides the following functions: .. function:: freeze() - Freeze all the objects tracked by gc - move them to a permanent generation - and ignore all the future collections. This can be used before a POSIX - 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 - allocation which can cause copy-on-write too so it's advised to disable gc - in parent process and freeze before fork and enable gc in child process. + Freeze all the objects tracked by the garbage collector; move them to a + permanent generation and ignore them in all the future collections. + + If a process will ``fork()`` without ``exec()``, avoiding unnecessary + copy-on-write in child processes will maximize memory sharing and reduce + 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 |