[Tutor] Trying to understand sys.getrefcount()
Alan Gauld
alan.gauld at btinternet.com
Fri Oct 13 09:55:49 CEST 2006
> class junk(object):
> ... pass
> ...
>>>> sys.getrefcount(junk)
> 5
> 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?
Because Python s holding 4 references to the class object internally.
For example the namespace dictionary will have one. I've no idea what
all the others will be but presumably thats whats happening. Remember
classes are objects too.
Alan G.
More information about the Tutor
mailing list