[PyQt] Memory Leak on findChild

Hayward, Anthony Anthony.Hayward at sagentia.com
Tue Sep 5 15:21:50 BST 2017

New PyQt5 user here.

I was hoping someone could let me know if I'm doing something wrong, or if I've found a bug in PyQt5?

In my full application, every time findChild() is called on the view, the application uses more memory. Here's a simple example that replicates the issue:

# memoryTest.qml:
import QtQuick 2.0

Item {
    id: dummy
    width: 100; height: 100;

# memoryTest.py
import sys
from PyQt5.QtQuick import QQuickView
from PyQt5.QtGui import QGuiApplication
from PyQt5.QtCore import QUrl, QObject, QTimer, pyqtSlot

class Controller(QObject):
    def __init__(self, view):
        """ Initialise the controller """

        self._view = view

        # Create timer loop to update the screen for text
        self._updateLoopTimer = QTimer()

    def myTestSlot(self):
        for _ in range(1000):
            thing = self._view.findChild(QObject, "aChildThatDontExist")

if __name__ == '__main__':
    # Create main app
    app = QGuiApplication(sys.argv)

    view = QQuickView()
    ctrl = Controller(view)
    view.rootContext().setContextProperty("ctrl", ctrl)

    # Wait till app closed

    # Exit this Python application

It doesn't seem to matter whether I call findChild() for an object that does or doesn't exist. The example above uses a bit under 400kB of memory a second.

Any help would be appreciated.

Thanks in advance,
This e-mail message is confidential and for use by the addressee only. If you are not the intended recipient, you must not use, disclose, copy or forward this transmission. Please return the message to the sender by replying to it and then delete the message from your computer. Sagentia provides e-mail services for both itself and its group companies. Sagentia shall not be held liable to any person resulting from the use of any information contained in this e-mail and shall not be liable to any person who acts or omits to do anything in reliance upon it. Sagentia does not accept responsibility for changes made to this message after it was sent.

Company Information: Name: Sagentia Limited. Registered Address: Harston Mill, Harston Cambridge CB22 7GG. Registered as a Company in England: 2081960 VAT Number: 432214202

More information about the PyQt mailing list