Reference counts
Helen Dawson
helend at accessone.com
Thu May 24 02:54:33 EDT 2001
The behaviour of getrefcount() seems odd on integers. I'm not
worried, just curious.
>>> import sys
>>> sys.getrefcount(0)
1495
>>> sys.getrefcount(15)
70
>>> sys.getrefcount(12341234)
2
I understand that the objects for numbers from 0 to 100 are shared,
but I find it unlikely that there are actually 1495 references to zero,
and 70 to 15. Zero is a popular number, but 1495? These results
are typical for absolutely nothing happening in Python
The refcount for 12341234 looks perfect. It is the minimum value
allowed for by the getrefcount docs, shown here:
>>> print sys.getrefcount.__doc__
getrefcount(object) -> integer
Return the current reference count for the object. This includes the
temporary reference in the argument list, so it is at least 2.
However, the problem with that is that getrefcount() for any negative
integer returns 1!
>>> sys.getrefcount(-2)
1
Any thoughts?
Bruce/Helen Dawson
More information about the Python-list
mailing list