memory leak with a QProcess
-
Hello,
I have a problem with QProcess. Every seconds, i launch an extern application and i observe a grow up of the memory.
I don't know why.I see that with QT 5.13 and 6.5
This is the code :
void MyClass::updateNtp() { _wasError = false; QProcess process; connect(&process, &QProcess::errorOccurred, this, &MyClass::launchErrorOccured); process.start("ntpq -p"); process.waitForFinished(-1); if (! _wasError ) { if ((process.exitStatus() == QProcess::NormalExit) && (process.exitCode() == 0)) { // Success, read the output QString output(process.readAllStandardOutput()); // .. further processings } } } void MyClass::launchErrorOccured(QProcess::ProcessError error) { _wasError = true; }
-
Hello,
I have a problem with QProcess. Every seconds, i launch an extern application and i observe a grow up of the memory.
I don't know why.I see that with QT 5.13 and 6.5
This is the code :
void MyClass::updateNtp() { _wasError = false; QProcess process; connect(&process, &QProcess::errorOccurred, this, &MyClass::launchErrorOccured); process.start("ntpq -p"); process.waitForFinished(-1); if (! _wasError ) { if ((process.exitStatus() == QProcess::NormalExit) && (process.exitCode() == 0)) { // Success, read the output QString output(process.readAllStandardOutput()); // .. further processings } } } void MyClass::launchErrorOccured(QProcess::ProcessError error) { _wasError = true; }
@MatthieuLC said in memory leak with a QProcess:
i observe a grow up of the memory
Do you mean the memory consumed by your application?
If so use a tool like Valgrind to see where the memory is leaking.
The code you posted should not leak, but you removed some peaces. -
Hello,
I have a problem with QProcess. Every seconds, i launch an extern application and i observe a grow up of the memory.
I don't know why.I see that with QT 5.13 and 6.5
This is the code :
void MyClass::updateNtp() { _wasError = false; QProcess process; connect(&process, &QProcess::errorOccurred, this, &MyClass::launchErrorOccured); process.start("ntpq -p"); process.waitForFinished(-1); if (! _wasError ) { if ((process.exitStatus() == QProcess::NormalExit) && (process.exitCode() == 0)) { // Success, read the output QString output(process.readAllStandardOutput()); // .. further processings } } } void MyClass::launchErrorOccured(QProcess::ProcessError error) { _wasError = true; }
-
Hello,
I have a problem with QProcess. Every seconds, i launch an extern application and i observe a grow up of the memory.
I don't know why.I see that with QT 5.13 and 6.5
This is the code :
void MyClass::updateNtp() { _wasError = false; QProcess process; connect(&process, &QProcess::errorOccurred, this, &MyClass::launchErrorOccured); process.start("ntpq -p"); process.waitForFinished(-1); if (! _wasError ) { if ((process.exitStatus() == QProcess::NormalExit) && (process.exitCode() == 0)) { // Success, read the output QString output(process.readAllStandardOutput()); // .. further processings } } } void MyClass::launchErrorOccured(QProcess::ProcessError error) { _wasError = true; }
@MatthieuLC said in memory leak with a QProcess:
Every seconds, i launch an extern application and i observe a grow up of the memory.
process.start("ntpq -p"); process.waitForFinished(-1);
From looking at the code and your issue, this is the only thing that came to my mind.
As @jsulm pointed out, there is no real memory leak.
However the memory might increase, when you start a new process every X (don't know what you mean by "every seconds") seconds and at the same timeprocess.waitForFinished(-1)
... which never timeouts and waits forever until process finishes.
Say, you call this update function every single second and some processes might take more than 10s to finish completely.
During that time you spawn 10 new processes, before the first one even finished. -
Sorry, I didn't make myself clear:
The method you see is invoked in a loop (from a specific thread). After its invocation, we wait 1 S before calling it again. Therefore, no further calls will be made until the previous call has been completed.The pseudo code would therefore be something like :
while (_isRunning) { updateNtp(); emit infoUpdated(); thread()->msleep(1000); }
What's most worrying is that it's not the memory of the QT application that's increasing, but Windows memory! And this, a priori, regardless of the executable invoked. With the sysinternal tools, we can see an increase in certain handles, at Windows level.
Thanks again for your help !
-
Sorry, I didn't make myself clear:
The method you see is invoked in a loop (from a specific thread). After its invocation, we wait 1 S before calling it again. Therefore, no further calls will be made until the previous call has been completed.The pseudo code would therefore be something like :
while (_isRunning) { updateNtp(); emit infoUpdated(); thread()->msleep(1000); }
What's most worrying is that it's not the memory of the QT application that's increasing, but Windows memory! And this, a priori, regardless of the executable invoked. With the sysinternal tools, we can see an increase in certain handles, at Windows level.
Thanks again for your help !
@MatthieuLC said in memory leak with a QProcess:
not the memory of the QT application that's increasing, but Windows memory
So it probably has nothing to do with Qt or being invoked from Qt.
Windows processes are going to take up room. That is where you need to ask. Have you checked that both the
ntpq
and anything it invokes have fully exited? It doesn't leave something around, or spawn anything which continues to run? How consistently does memory rise? Does it just rise without limit over time or does it plateau after a few invocations? What happens if you keep running outside of a Qt app? What happens if the program you spawn from Qt is something else, like, I don't know,dir
?