[Interest] QJsonObject memory leak?

Nuno Santos nuno.santos at imaginando.pt
Thu Nov 2 16:51:43 CET 2023


Hi,

I have realised that I cannot release all the memory allocated by a huge QJsonObject when I don’t need it any more. To ensure that nothing else was in between I have created a simple program that does what is below. Conclusion:

- Running on a Mac, compiled in release with Qt 6.5.3

- Starts with 31.7 MB



- Goes up to 412.5 MB



- After calling uncreate drops to 42.7




If I repeat this procedure, it always increases the process memory size although it is not linear.

In iOS the problem is even worse.

Any ideas of what is happening here?

Thank you!

Best regards,

Nuno


QString GetRandomString()
{
    const QString possibleCharacters("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
    const int randomStringLength = 4096; // assuming you want random strings of 12 characters
    
    QString randomString;
    for(int i=0; i<randomStringLength; ++i)
    {
        int index = QRandomGenerator::global()->generate() % possibleCharacters.length();
        QChar nextChar = possibleCharacters.at(index);
        randomString.append(nextChar);
    }
    
    return randomString;
}

void Controller::create()
{
    qDebug() << Q_FUNC_INFO;

    for (int i=0; i<100000; i++)
        _data[QString::number(i)] = GetRandomString();
}

void Controller::uncreate()
{
    qDebug() << Q_FUNC_INFO;

    _data = QJsonObject();
}


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20231102/866790f4/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot 2023-11-02 at 15.48.29.png
Type: image/png
Size: 4473 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20231102/866790f4/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot 2023-11-02 at 15.48.43.png
Type: image/png
Size: 4646 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20231102/866790f4/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot 2023-11-02 at 15.48.50.png
Type: image/png
Size: 4549 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20231102/866790f4/attachment-0002.png>


More information about the Interest mailing list