In CPython 3.11, the following code returns very large reference counts for some objects. It seems to follow pre-cached objects like integers -5 to 256, but CPython 3.10 does not:
Python 3.11.2 (tags/v3.11.2:878ead1, Feb 7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> for i in (-6, -5, 0, 255, 256, 257):
... print(i, sys.getrefcount(i))
...
-6 5
-5 1000000004
0 1000000535
255 1000000010
256 1000000040
257 5
Python 3.10.8 (tags/v3.10.8:aaaf517, Oct 11 2022, 16:50:30) [MSC v.1933 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> for i in (-6, -5, 0, 255, 256, 257):
... print(i, sys.getrefcount(i))
...
-6 5
-5 6
0 234
255 8
256 26
257 5
PEP 683 - Immortal Objects, Using a Fixed Refcount may be related, but it isn't mentioned in What's New in Python 3.11, nor is a change in sys.getrefcount()
documented.
Anybody have knowledge about this change?