Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. memory leak with a QProcess
Forum Updated to NodeBB v4.3 + New Features

memory leak with a QProcess

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 597 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MatthieuLC
    wrote on last edited by
    #1

    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;
    } 
    
    jsulmJ JonBJ Pl45m4P 3 Replies Last reply
    0
    • M MatthieuLC

      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;
      } 
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M MatthieuLC

        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;
        } 
        
        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • M MatthieuLC

          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;
          } 
          
          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by Pl45m4
          #4

          @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 time process.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.


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          1 Reply Last reply
          1
          • M Offline
            M Offline
            MatthieuLC
            wrote on last edited by
            #5

            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 !

            JonBJ 1 Reply Last reply
            0
            • M MatthieuLC

              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 !

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @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?

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved