8000 Update section on untracking · python/cpython@db2e173 · GitHub
[go: up one dir, main page]

Skip to content

Commit db2e173

Browse files
committed
Update section on untracking
1 parent f043080 commit db2e173

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

InternalDocs/garbage_collector.md

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,8 @@ of `PyGC_Head` discussed in the `Memory layout and object structure`_ section:
520520
currently in. Instead, when that's needed, ad hoc tricks (like the
521521
`NEXT_MASK_UNREACHABLE` flag) are employed.
522522

523-
Optimization: delay tracking containers
524-
=======================================
523+
Optimization: delayed untracking containers
524+
===========================================
525525

526526
Certain types of containers cannot participate in a reference cycle, and so do
527527
not need to be tracked by the garbage collector. Untracking these objects
@@ -536,8 +536,8 @@ a container:
536536
As a general rule, instances of atomic types aren't tracked and instances of
537537
non-atomic types (containers, user-defined objects...) are. However, some
538538
type-specific optimizations can be present in order to suppress the garbage
539-
collector footprint of simple instances. Some examples of native types that
540-
benefit from delayed tracking:
539+
collector footprint of simple instances. Historically, both dictionaries and
540+
tuples were untracked during garbage collection. Now it is only tuples:
541541

542542
- Tuples containing only immutable objects (integers, strings etc,
543543
and recursively, tuples of immutable objects) do not need to be tracked. The
@@ -546,14 +546,8 @@ benefit from delayed tracking:
546546
tuples at creation time. Instead, all tuples except the empty tuple are tracked
547547
when created. During garbage collection it is determined whether any surviving
548548
tuples can be untracked. A tuple can be untracked if all of its contents are
549-
already not tracked. Tuples are examined for untracking in all garbage collection
550-
cycles. It may take more than one cycle to untrack a tuple.
551-
552-
- Dictionaries containing only immutable objects also do not need to be tracked.
553-
Dictionaries are untracked when created. If a tracked item is inserted into a
554-
dictionary (either as a key or value), the dictionary becomes tracked. During a
555-
full garbage collection (all generations), the collector will untrack any dictionaries
556-
whose contents are not tracked.
549+
already not tracked. Tuples are examined for untracking when moved from the
550+
young to the old generation.
557551

558552
The garbage collector module provides the Python function `is_tracked(obj)`, which returns
559553
the current tracking status of the object. Subsequent garbage collections may change the
@@ -566,11 +560,9 @@ tracking status of the object.
566560
False
567561
>>> gc.is_tracked([])
568562
True
569-
>>> gc.is_tracked({})
563+
>>> gc.is_tracked(("a": 1))
570564
False
571565
>>> gc.is_tracked({"a": 1})
572-
False
573-
>>> gc.is_tracked({"a": []})
574566
True
575567
```
576568

0 commit comments

Comments
 (0)
0