Help on sys.getrefcount
Christoph Becker-Freyseng
christoph at mmc-startup.com
Thu Mar 6 07:01:57 EST 2003
Hello,
I wrote the following test-program:
import sys
l= ['x', 'y', 'z', 'a']
for iR in l:
refD= sys.getrefcount(iR)
print str(iR) + '::' + str(refD)
It's output is:
x::7
y::7
z::7
a::8
I expected the output to be:
x::3
y::3
z::3
a::3
I don't see why the refcount is so high (7 or 8 instead 3).
What's even more strange to me is: Why is the refcount for 'a' higher
than for e.g. 'x'?
This also is the fact when the order of the list is changed:
import sys
l= ['x', 'y', 'a', 'z']
for iR in l:
refD= sys.getrefcount(iR)
print str(iR) + '::' + str(refD)
Output:
x::7
y::7
a::8
z::7
This happens with Python 2.0 on SuSE Linux 7.3 with 2.218 Kernel.
Many Thanks,
Christoph Becker-Freyseng
More information about the Python-list
mailing list