[PyKDE] Bad Memory Leak
rasky at develer.com
Wed Dec 6 11:03:26 GMT 2006
Andreas Pakulat wrote:
> Note this is python, not C++, del foobar doesn't immediately free the
> memory associated.
That's incorrect. "del foobar" removes a reference; if it's the last
reference and there are no loops, the memory is immediately collected. Now,
there are no reference loops at the Python level, so the memory *is*
collected when the "del" statement is executed.
Specifically, the first "del b" collected the Python-side instance of the
push button (the C++-side of the pushbutton is owned by the dialog as it's a
chiled). The second "del d" collects the Python-side instance of the dialog,
which in turns causes a deletion of the C++-side of the dialog (since it has
no parent, so it's fully owned by Python); the C++ destructor also destroys
the C++-side of the pushbutton. So, after the second "del", all the memory
is reclaimed, with no need for the Python cyclic GC to kick in.
More information about the PyQt