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

QMap<int,QVector> does not release memory

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: Not Evaluated Not Evaluated
    • None
    • 5.15.2, 6.4.2
    • None
    • Linux Mint 20.3
    • Linux/X11

      When a QVectors are stored in a QMap, the memory is not released in QMap destructor. Here's a simple example to reproduce the issue:

       

      #include <QCoreApplication>
      #include <QMap>
      #include <QTimer>
      #include <QVector>
      using Line = QVector<int>;
      using Map = QMap<qint64, Line>;
      int main(int argc, char *argv[]) {
        QCoreApplication a(argc, argv);
        QTimer timer;
        QObject::connect(&timer, &QTimer::timeout, []() {
          Map map;
          for (qint64 i = 0; i < 1000000; ++i)
            map[i] = Line(100000);
        });
        timer.start(10);
        return a.exec();
      }
      

      The example provided is expected to allocate memory and release it as soon as map variable goes out of scope. Yet the memory is never released, causing the program to consume all available memory and crash.

      Replacing QMap and QVector with std::map and std::vector respectively yields the same result. But when the internal QVector is replaced with a string (for example), the memory is released as expected.

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

            thiago Thiago Macieira
            kdidkovsky Kirill V. Didkovsky
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes