Reference counts

Duncan Booth duncan at NOSPAMrcp.co.uk
Thu May 24 11:28:13 CEST 2001


Helen Dawson <helend at accessone.com> wrote in 
news:3B0CB0B6.EA9D2EF1 at accessone.com:

> 
>>>> 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

Actually they aren't. On my system python with absolutely nothing 
happening:
Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.getrefcount(0)
49

Python running idle:
Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>> import sys
>>> sys.getrefcount(0)
388

And finally running PythonWin:
PythonWin 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32.
Portions Copyright 1994-2001 Mark Hammond (MarkH at ActiveState.com) - see 
'Help/About PythonWin' for further copyright information.
>>> import sys
>>> sys.getrefcount(0)
1137
>>> 

So whatever you were running was doing even more nothing than PythonWin 
which has 1137 nothings (and 3138 references to None).

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?



More information about the Python-list mailing list