@@ -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
526526Certain types of containers cannot participate in a reference cycle, and so do
527527not need to be tracked by the garbage collector. Untracking these objects
@@ -536,8 +536,8 @@ a container:
536536As a general rule, instances of atomic types aren't tracked and instances of
537537non-atomic types (containers, user-defined objects...) are. However, some
538538type-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
558552The garbage collector module provides the Python function ` is_tracked(obj) ` , which returns
559553the 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