[Tutor] Trying to understand sys.getrefcount()

Tony Cappellini cappy2112 at gmail.com
Fri Oct 13 00:48:25 CEST 2006


I'm using Python 2.3.4

After reading this in the docs
 *getrefcount*( object) Return the reference count of the object. The count
returned is generally one higher than you might expect, because it includes
the (temporary) reference as an argument to getrefcount().I decided to try
some experiments

 class junk(object):
...     pass
...
>>> sys.getrefcount(junk)
5
>>> j1=junk()
>>> sys.getrefcount(junk)
6

sys.getrefcount(j1)
2

I understand why j1 is 1 higher than I expect, based on the docs, but why
does getrefcount(junk) return 5 before any instances of class junk are made?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061012/58a078c1/attachment-0001.htm 


More information about the Tutor mailing list