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

Memory leak when using font rendering in different threads and destroying the threads

    XMLWordPrintable

Details

    Description

      QFontCache::~QFontCache (qfont.cpp) enters the "QFontCache::~QFontCache: engine = %p still has refcount %d" path. I don't know why the font engine still has a refcount at this point.

      This example reproduces the leak:

      #include <QtGui>
      #include <QtDebug>

      class MyWidget : public QWidget
      {
      Q_OBJECT
      public:
      MyWidget();
      private slots:
      void slotprint();

      private:
      QLineEdit *m_edit;
      QPushButton *m_print;
      };

      MyWidget::MyWidget()
      {
      QVBoxLayout* mainLayout = new QVBoxLayout(this);
      m_print = new QPushButton("print");
      connect(m_print, SIGNAL(clicked()), this, SLOT(slotprint()));
      m_edit = new QLineEdit;
      mainLayout->addWidget(m_print);
      mainLayout->addWidget(m_edit);
      }

      class PrintThread : public QThread
      {
      public:
      PrintThread(QObject* parent)
      : QThread(parent)
      {
      }

      void run()

      { QImage image(128, 128, QImage::Format_ARGB32_Premultiplied); image.fill(0x0); QPainter p(&image); QTextDocument document; document.setPlainText(QLatin1String("render this string")); document.drawContents(&p); }

      };

      void MyWidget::slotprint()
      {
      PrintThread* thread = new PrintThread(this);

      connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
      connect(thread, SIGNAL(finished()), this, SLOT(slotprint()));

      m_edit->setText("foo");
      m_print->setEnabled(false);

      thread->start();
      }

      int main(int argc, char *argv[])
      {
      QApplication app(argc, argv);

      MyWidget* widget = new MyWidget();
      widget->show();

      return app.exec();
      }

      #include "main.moc"

      Attachments

        Issue Links

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

          Activity

            People

              esabraha Eskil Abrahamsen Blomfeldt
              rodal Samuel Rødal
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes