counting references to an instance

Michael Hudson mwh at python.net
Thu Feb 5 07:32:35 EST 2004


Thomas Heller <theller at python.net> writes:

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

In *all* builds, there's sys.getrefcount().  Are you thinking of
sys.gettotalrefcount()?

-- 
  ARTHUR:  Yes.  It was on display in the bottom of a locked filing
           cabinet stuck in a disused lavatory with a sign on the door
           saying "Beware of the Leopard".
                    -- The Hitch-Hikers Guide to the Galaxy, Episode 1



More information about the Python-list mailing list