[PyQt] Memory Leak on findChild

Cody Scott cody at perspexis.com
Tue Sep 5 16:00:25 BST 2017


I can confirm that this continues to use more memory on both Windows and
Linux using the latest PyPI release.


On Tue, Sep 5, 2017 at 10:21 AM, Hayward, Anthony <
Anthony.Hayward at sagentia.com> wrote:

> 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 """
>         QObject.__init__(self)
>
>         self._view = view
>
>         # Create timer loop to update the screen for text
>         self._updateLoopTimer = QTimer()
>         self._updateLoopTimer.timeout.connect(self.myTestSlot)
>         self._updateLoopTimer.start(1000)
>
>     @pyqtSlot()
>     def myTestSlot(self):
>         for _ in range(1000):
>             thing = self._view.findChild(QObject, "aChildThatDontExist")
>         print(thing)
>
> if __name__ == '__main__':
>     # Create main app
>     app = QGuiApplication(sys.argv)
>
>     view = QQuickView()
>     ctrl = Controller(view)
>     view.setSource(QUrl("memoryTest.qml"))
>     view.rootContext().setContextProperty("ctrl", ctrl)
>     view.show()
>
>     # Wait till app closed
>     app.exec_()
>
>     # Exit this Python application
>     sys.exit()
>
>
>
> 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,
> Anthony
> ________________________________
> 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
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170905/eaafda4c/attachment.html>


More information about the PyQt mailing list