New GitHub issue #101265 from ericsnowcurrently:<br>

<hr>

<pre>
The runtime currently has many objects that are statically defined.  See Include/internal/pycore_global_objects.h.  For the singletons, all instances of the type are statically defined.  Otherwise only some instances are.

<details>
<summary>(affected types)</summary>

The following types are those that have only some statically defined instances (not counting deep-frozen objects):

* `int`
* `bytes`
* `str`
* `tuple`

Deepfreeze adds the following:

* `float`
* `complex`
* `slice`
* `code`
* (more `bytes`, `int`, `tuple`, & `str` objects)

</details>

The problem is that if `tp_dealloc()` for one of the affected types tries to free a static object then it will crash.  We've set the refcount for such objects to a really high number to avoid this, but it is still possible.  The risk rises a bit for immortal objects (see PEP 683).

For all types with static objects, we need to add a check in `tp_dealloc()` to either fail or reset the refcount to the really high number.  We already have a check like this for the singletons and for `str`.  For the other types we need to identify if the object is static and respond accordingly.  The catch is that identifying that can be expensive, which is problematic for types that are deallocated frequently.
</pre>

<hr>

<a href="https://github.com/python/cpython/issues/101265">View on GitHub</a>
<p>Labels: type-feature, 3.12</p>
<p>Assignee: </p>