counting references to an instance

Thomas Heller theller at python.net
Wed Feb 4 14:36:11 EST 2004


Brian <balex at sympatico.ca> writes:

> Hello;
>
> Is it possible to get an object to return the number of references there
> are to itself?
>
> Ex:
>
> class test(object):
>  pass
>
> a = test()
> b = a
>
> # Should print "2", if I knew the name of the method.
> print a.refCount()
>

In Python debug builds, there's the sys.getrefcount() function.

Thomas



More information about the Python-list mailing list