[Interest] QJsonObject memory leak?

Elvis Stansvik elvstone at gmail.com
Thu Nov 2 17:28:53 CET 2023


Can you create a standalone example? (I see no calls to your
create/uncreate)

How are you measuring memory consumption?

Elvis

Den tors 2 nov. 2023 16:52Nuno Santos <nuno.santos at imaginando.pt> skrev:

> 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
>
> [image: Screenshot 2023-11-02 at 15.48.29.png]
>
> - Goes up to 412.5 MB
>
> [image: Screenshot 2023-11-02 at 15.48.43.png]
>
> - After calling uncreate drops to 42.7
>
> [image: Screenshot 2023-11-02 at 15.48.50.png]
>
>
> 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();
> }
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> https://lists.qt-project.org/listinfo/interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20231102/f525630a/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/f525630a/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/f525630a/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/f525630a/attachment-0002.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/f525630a/attachment-0003.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/f525630a/attachment-0004.png>
-------------- 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/f525630a/attachment-0005.png>


More information about the Interest mailing list