473,288 Members | 2,725 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,288 software developers and data experts.

Trouble finding references that are keeping objects alive

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

Sep 1 '06 #1
1 1470
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

Sep 1 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: J-P | last post by:
Hi, I have a Python script interacting with a specialized C numerical library. The whole program does quite a lot of number crunching as should be running for a couple of hours. However, it...
4
by: Jacek Dziedzic | last post by:
Hi! First of all, I hope my problem is not too loosely tied to the "standard C++" that is the topic of this group. I have some code that exhibits a strange behaviour: on one computer, where I...
10
by: Hendri Adriaens | last post by:
Hi, I'm trying to automate the creation of an excel file via COM. I copied my code below. I read many articles about how to release the COM objects that I create. The code below runs just fine...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.