[PyKDE] Re: Memory leak & segfault with deleteLater

Phil Thompson phil at riverbankcomputing.co.uk
Tue Jun 21 08:23:48 BST 2005

> Phil Thompson <phil at riverbankcomputing.co.uk> wrote:
>> I'm not sure if anything can be done to detect and/or prevent the
>> problem.
>> It would be easy enough to contrive the same problem in C++, so I don't
>> really see it as a PyQt problem. I'm open to suggestions.
> What about adding adding a flag (static variable in the derived
> destructor)
> which records if we are already destroying the object? So that, if the
> derived destructor gets re-invoked as part of a reference cycle, it just
> silently exits without doing anything. I think you have a similar
> variable,
> which records if the C++-side of the object is destroyed or not... maybe
> you
> could set that at the very start of the derived destructor.

But that would be too late wouldn't it? You are still going to get a
double free of the object.

I think one way around the problem is to avoid the extra reference to the
Python object and move the data that it contains into a separate data
structure. In other words, weaken the link between the Python world and
the C++ world. My concern would then be stopping the new data structure
leaking - I need to think about it a bit more.


More information about the PyQt mailing list