[PyQt] Hunting down memory leaks

Kovid Goyal kovid at kovidgoyal.net
Tue Dec 14 18:46:06 GMT 2010

If you are using lambdas or partials as slots to connect to, you can very easily create reference cycles that the garbage collector wont be able to clear. For example, say you have a widget with a button and a method react_to_button_press and you do something like

class Widget(QWidget):

    def __init__(self):

        self.button.clicked.connect(partial(self.react_to_button_press, 1))

This means any Widget objects will never be garbage collected, unless you explicitly disconnect the signal. 


On Mon, Dec 13, 2010 at 09:49:55PM +1100, Mikael Modin wrote:
> Hi,
> I'm currently developing a little tool and it seems I have a memory
> leak somewhere along the line that handles images, so each leak is
> around 7mb which is kind of a big deal leading my app quickly to
> 100mb. I'm wondering if any of you havea any tips to figure out what
> kind of object I'm leaking and where I'm leaking them. I'm new to
> python, Qt and PyQt so I'm not very well versed in what tools are
> available.
> Kind regards
> Mikael
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
> !DSPAM:3,4d05fa8d13992044411110!


Dr. Kovid Goyal 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20101214/abac0601/attachment.pgp>

More information about the PyQt mailing list