watching the number of references to an object

Michael Hudson mwh at
Thu Feb 14 17:02:45 CET 2002

"Paul Brian" <paul1brian at> writes:

> Dear all,
> Does anyone know how to monitor the references pointing to an instance of an
> object?
> the gc module (according to docs) seems to show those with no
> references left, but I am interested in seeing how many refs a given
> instance has...any ideas on back of a postcard please

You want gc.get_referrers (new in 2.2, I think), or maybe just

>>> import gc
>>> len(gc.get_referrers(gc))

(the referrers are going to be sys.modules & __main__.__dict__ here).


  at any rate, I'm satisfied that not only do they know which end of
  the pointy thing to hold, but where to poke it for maximum effect.
                                  -- Eric The Read, asr, on

More information about the Python-list mailing list