Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-63144

I found some memory leaks when using serial port in Qt5.7.0

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P2: Important
    • None
    • 5.7.0
    • None
    • Qt Creator 4.0.2 + Qt 5.7.0 + MSVC2013

    Description

      when I synchronously wrote and read data by serial port in a  single thread,  I found that the memory of program continually increased at a speed of 4 KB per second, and it's not clear why it happend.

      I tried to clear input and output buffer after read data ,but it did not work. Besides, i have used other Library like QextSerialPort, and there's no memory leak.

      So please kindly show me how can i solve this problem, thanks.

      The test code follows:


      Unable to find source-code formatter for language: c++. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
      
      class QOriginSerialPort : public QThread
      {
          Q_OBJECT
      public:
          QOriginSerialPort(QObject* parent = 0) : QThread(parent){}
          ~QOriginSerialPort() {
              this->requestInterruption();
              quit();
              wait();
          }
      
      protected:
          void run(){
              QSerialPort serial;
              serial.setPortName("COM1");
              if(!serial.open(QIODevice::ReadWrite)){       //open serial port
                  return;
              }
      
              serial.setBaudRate(QSerialPort::Baud115200);
              serial.setDataBits(QSerialPort::Data8);
              serial.setParity(QSerialPort::EvenParity);
              serial.setFlowControl(QSerialPort::NoFlowControl);
              serial.setStopBits(QSerialPort::OneStop);
              //serial.setReadBufferSize(10);
      
              QByteArray data;
              establishProtocol(2,data);  
      
              forever{
                 serial.write(data);
                 serial.waitForBytesWritten(2);
                  if(serial.waitForReadyRead(20)){
                      QByteArray bytes = serial.readAll();
                  }
      
                  if(isInterruptionRequested())
                      break;
      
                  msleep(1);
              }
      
              serial.close();
          }
      };
      

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            kuzulis Denis Shienkov
            ericli ERIC LI
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes