How to check what is holding reference to object

Almar Klein almar.klein at
Tue Apr 27 16:58:23 EDT 2010

> I've just found out that one of objects is not destroyed when it
> should be. This means that something was holding reference to this
> object or part of it (i.e. method). Is there any way to check what
> holds that reference? I am unable to do that just looking to the code
> or debugging it because it is pretty complicated, but I am able to
> invoke this situation again.

I don't think that's possible, since that would mean Python would need to
keep a reference to the object holding the reference, which seems pretty

You can however, obtain the number of referencing objects using
sys.getrefcount(object). You have to subtract 1 from the result, as the
function itself of course holds a reference to at the moment it is being

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list