[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Attempting to reduce the memory footprint of my PyQt5 application
From:       Xavion <xavion.0 () gmail ! com>
Date:       2016-09-15 0:14:13
Message-ID: CAKnx8Y6TbrH4_VCqbbiP-hpyH40mQ-c-B84p4ihXKxdUdjiexg () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Okay, I've found the time to do some more testing on this.  Pympler wasn't
able to find any memory leaks, but that could've just meant that I wasn't
using it properly.  Either way, the good news is that I've managed to find
the source of the leak manually.

Basically, I've got a QTimer which triggers the (re)starting of a QThread
instance every 15 seconds.  Said thread creates a QProcess, which runs a
shell command and collects its output.  The QProcess is then destroyed and
the memory is (supposedly) freed.

However, despite this arrangement, the memory usage of my application still
goes up by about 4 KiB each time the QThread is run.  While this may sound
insignificant, bear in mind that said application is intended to run for
days on end (in the system tray).  Over the period of a week, the memory
increase would be roughly 160 MiB.  One of my users has reported seeing
exactly this (and more, the longer it goes on).

No matter what I try, I can't seem to stop it from happening.  Even with
the following code, the memory footprint still increases by the same amount
each time the QThread is run.

pStatus = QtCore.QProcess()
pStatus.start(sCommand, sArgs)
pStatus.waitForStarted(500)
while not pStatus.waitForFinished(500) :

pass

pStatus.deleteLater()
gc.collect()
self.exit()


However, note that merely creating the QProcess (i.e. running the first
line of code by itself) doesn't result in any ongoing increase in memory.
This leads me to believe that the leak has something to do with the
execution of the shell command.  Does anyone know how to make it go away?

[Attachment #5 (text/html)]

<div dir="ltr"><div class="gmail_extra"><div class="gmail_signature"><div><font \
size="2" color="#000000">Okay, I&#39;ve found the time to do some more testing on \
this.   Pympler wasn&#39;t able to find any memory leaks, but that could&#39;ve just \
meant that I wasn&#39;t using it properly.   Either way, the good news is that \
I&#39;ve managed to find the source of the leak manually.</font></div><div><font \
size="2" color="#000000"><br></font></div><div><font size="2" \
color="#000000">Basically, I&#39;ve got a QTimer which triggers the (re)starting of a \
QThread instance every 15 seconds.   Said thread creates a QProcess, which runs a \
shell command and collects its output.   The QProcess is then destroyed and the \
memory is (supposedly) freed.</font></div><div><font size="2" \
color="#000000"><br></font></div><div><font color="#000000">However, despite this \
arrangement, the memory usage of my application still goes up by about 4 KiB each \
time the QThread is run.   While this may sound insignificant, bear in mind that said \
application is intended to run for days on end (in the system tray).   Over the \
period of a week, the memory increase would be roughly 160 MiB.   One of my users has \
reported seeing exactly this (and more, the longer it goes \
on).</font></div><div><font color="#000000"><br></font></div><div><font \
color="#000000">No matter what I try, I can&#39;t seem to stop it from happening.   \
Even with the following code, the memory footprint still increases by the same amount \
each time the QThread is run.</font></div></div></div><blockquote style="margin:0px \
0px 0px 40px;border:none;padding:0px"><div class="gmail_extra"><div \
class="gmail_signature"><div><font color="#000000">pStatus = \
QtCore.QProcess()<br></font></div><div><font color="#000000">pStatus.start(sCommand, \
sArgs)<br></font></div><div><font \
color="#000000">pStatus.waitForStarted(500)<br></font></div><div><font \
color="#000000">while not pStatus.waitForFinished(500) \
:<br></font></div></div></div></blockquote><blockquote style="margin:0px 0px 0px \
40px;border:none;padding:0px"><blockquote style="margin:0px 0px 0px \
40px;border:none;padding:0px"><div class="gmail_extra"><div \
class="gmail_signature"><div><font \
color="#000000">pass</font></div></div></div></blockquote></blockquote><blockquote \
style="margin:0px 0px 0px 40px;border:none;padding:0px"><font \
color="#000000">pStatus.deleteLater()<br>gc.collect()<br>self.exit()<br></font></blockquote><div \
class="gmail_extra"><div class="gmail_signature"><div><br></div><div>However, note \
that merely creating the QProcess (i.e. running the first line of code by itself) \
doesn&#39;t result in any ongoing increase in memory.   This leads me to believe that \
the leak has something to do with the execution of the shell command.   Does anyone \
know how to make it go away?</div><div><br></div></div> </div></div>


[Attachment #6 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic