
On Thu, 16 Dec 2021 23:32:17 +1100 Steven D'Aprano <steve@pearwood.info> wrote:
On Thu, Dec 16, 2021 at 12:23:09PM +0100, Antoine Pitrou wrote:
The "real number of references" would not be known for immortal objects.
Oh that surprises me. How does that work? Does that imply that some code might not increment the ref count, while other code will?
If an object is immortal, then its refcount wouldn't change at all. « Some objects, such as interned strings, small integers, statically allocated PyTypeObjects, and the True, False, and None objects stay alive for the lifetime of the program. These objects are marked as immortal by setting the least-significant bit of the local reference count field (bit 0). The Py_INCREF and Py_DECREF macros are no-ops for these objects. This avoids contention on the reference count fields of these objects when they are accessed concurrently by multiple threads. » Regards Antoine.