@@ -520,8 +520,8 @@ of `PyGC_Head` discussed in the `Memory layout and object structure`_ section:
520
520
currently in. Instead, when that's needed, ad hoc tricks (like the
521
521
` NEXT_MASK_UNREACHABLE ` flag) are employed.
522
522
523
- Optimization: delay tracking containers
524
- =======================================
523
+ Optimization: delayed untracking containers
524
+ ===========================================
525
525
526
526
Certain types of containers cannot participate in a reference cycle, and so do
527
527
not need to be tracked by the garbage collector. Untracking these objects
@@ -536,8 +536,8 @@ a container:
536
536
As a general rule, instances of atomic types aren't tracked and instances of
537
537
non-atomic types (containers, user-defined objects...) are. However, some
538
538
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 :
541
541
542
542
- Tuples containing only immutable objects (integers, strings etc,
543
543
and recursively, tuples of immutable objects) do not need to be tracked. The
@@ -546,14 +546,8 @@ benefit from delayed tracking:
546
546
tuples at creation time. Instead, all tuples except the empty tuple are tracked
547
547
when created. During garbage collection it is determined whether any surviving
548
548
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.
557
551
558
552
The garbage collector module provides the Python function ` is_tracked(obj) ` , which returns
559
553
the current tracking status of the object. Subsequent garbage collections may change the
@@ -566,11 +560,9 @@ tracking status of the object.
566
560
False
567
561
>>> gc.is_tracked([])
568
562
True
569
- >>> gc.is_tracked({} )
563
+ >>> gc.is_tracked(("a": 1) )
570
564
False
571
565
>>> gc.is_tracked({"a": 1})
572
- False
573
- >>> gc.is_tracked({"a": []})
574
566
True
575
567
```
576
568
0 commit comments