At 03:25 AM 10/3/2006, Andre Roberge wrote:
10/3/06, **** Moores <rdm (AT) rcblue (DOT) comwrote:
Is there Python code for accessing an object's reference count?
>
>See sys.getrefcount.
Fascinating. And surprising.
from sys import getrefcount
getrefcount(1)
493
getrefcount(2)
157
getrefcount(3)
60
getrefcount(22)
12
getrefcount(222)
3
getrefcount(222234523452345345)
2
getrefcount(2.23452345345)
2
That refcount for 1 (and 2, 3, and 12) is puzzling to me. I closed
python, called python, and tried it again. Essentially no change.
When would this go to zero? when I shut off my computer?
I just answered that last question by shutting off my computer, and found
from sys import getrefcount
getrefcount(1)
493
q = 1
getrefcount(1)
499
w = 1
getrefcount(1)
500
del w
getrefcount(1)
499
q = 2
getrefcount(1)
498
Still 493. Why?
Then after "q = 1", 499, not 494. Why?
The other refcounts, after w=1, del w, and q=2, are as I expected.
Thanks,
****
Tutor maillist - Tutor (AT) python (DOT) org