0

I have a large python code base.

At one point I find out (using guppy but that doesn't really matter) that I have an existing instance of my class BigClass.

At this point of the code I do not expect to have any living instances of BigClass since all of them were supposed to be released. I tried calling gc.collect()

How can I trace down where is this instance, why is it still alive, its properties and so on?

user972014
  • 3,296
  • 6
  • 49
  • 89

1 Answers1

0

You can find all instances of the class:

for obj in gc.get_objects():
    if isinstance(obj, BigClass):
        # DEBUG IT

For debugging the actual objects and how are they referenced:

for ref in gc.get_referrers(obj):
    # Should probably filter here to reduce the amount of data printed and avoid printing locals() as well
    print(ref)
user972014
  • 3,296
  • 6
  • 49
  • 89