Details
-
Bug
-
Resolution: Cannot Reproduce
-
Not Evaluated
-
None
-
5.15.2, 6.4.2
-
None
-
Linux Mint 20.3
Description
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.