Trouble finding references that are keeping objects alive

2006-08-31 Thread 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

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trouble finding references that are keeping objects alive

2006-08-31 Thread 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

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: AttributeError: 'Attributes' object has no attribute 'saveFile'

2006-08-31 Thread t . mitchell
Hi

Sounds like you've got a wizard-type interface thing happening.
I haven't used wxGlade but I have done similar things in GTK several
times.

Try putting all the windows in a notebook widget with hidden tabs.
Put the 'Next Page' button and the filename outside the notebook.  This
makes the filename always available and the 'Next Page' button would
just switch pages in the notebook widget.

Hope this is helpful

Cheers
Tim

-- 
http://mail.python.org/mailman/listinfo/python-list