Trouble finding references that are keeping objects alive

t.mitchell at aranz.com t.mitchell at aranz.com
Thu Aug 31 20:16:20 EDT 2006


Hi,

I have a python gtk app that allows users to have one project open at a
time.  I have recently discovered that projects are not being freed
when they are closed - the refcount is not hitting zero.  I have used
gc.get_referrers() to track down a few culprits, but I have now found
that some of my dialog boxes are staying alive after being closed too
(and keeping a reference to the project).
e.g.
            gc.collect()
            print sys.getrefcount(self.data.project)
            # this function presents the dialog and loads the data
            idata = csvimport.ask_and_load(self.app.root,
self.data.project)
            gc.collect()
            print sys.getrefcount(self.data.project)

prints out:
39
40

(In this example I have cancelled the dialog and idata is None.)

I have tracked down an offending tuple that has a reference to my
dialog, which is a value in a large dictionary with integer keys that
look like ID's. The other values in the dictionary appear to be widget
connections and other stuff.

Anyway, gc.get_referrers() keeps giving me lists, dictionarys and
frames, which is not helping me find what code created this reference.

I can't think of any other way of tracking this down apart from hacking
some debug code into the python source.
Does anyone have any other ideas for finding the code that created my
unwanted reference before I have to dust off my C skills?

Thanks
Tim




More information about the Python-list mailing list