Trouble finding references that are keeping objects alive

T

t.mitchell

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
 
T

t.mitchell

More info:
The project has cyclic references to the objects in the projects, but
this should be handled by gc.collect(). Here's is my 'project still
alive' test:

# store a weakref for debugging
p = weakref.ref(self.data.project)
self.data.setProject(None, None)
gc.collect() # whole project is cyclic
p = p()
if p is not None:
print 'Project still exists!!'

Cheers
Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top