Python Forum
python cache for small integer - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: python cache for small integer (/thread-19418.html)



python cache for small integer - Uchikago - Jun-27-2019

I know there is a cache to hold for small integers [-5,256] but when i try to get reference count for a big number like:
>>> import sys
>>> sys.getrefcount(2323232323)
3
>>>
Why the result is 3 ? Are there some "internal variables" hold this value inside python ?. It doesn't make sense, i thought a new value is only created when we make a new assignment(expect for those in [-5,256])in our script.Furthermore, how can python's garbage collector collect these value ? Because they always have "internal variables" point to them and their reference counter never drop to 0 .Please help me out, guys Sad


RE: python cache for small integer - ichabod801 - Jun-27-2019

It looks like the three includes the reference in the getrefcount call, one in the interactive interpreter, and one for optimization purposes. See this stack overflow.