Python Forum

Full Version: python cache for small integer
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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.