[Interest] QJsonObject memory leak?

Nuno Santos nuno.santos at imaginando.pt
Thu Nov 2 19:53:53 CET 2023


Elvis,

The test follows attached.

Best,

Nuno



> On 2 Nov 2023, at 16:28, Elvis Stansvik <elvstone at gmail.com> wrote:
> 
> 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 <mailto: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
>> 
>> 
>> 
>> - 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();
>> }
>> 
>> 
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org <mailto:Interest at qt-project.org>
>> https://lists.qt-project.org/listinfo/interest
> <Screenshot 2023-11-02 at 15.48.43.png><Screenshot 2023-11-02 at 15.48.29.png><Screenshot 2023-11-02 at 15.48.50.png><Screenshot 2023-11-02 at 15.48.29.png><Screenshot 2023-11-02 at 15.48.29.png><Screenshot 2023-11-02 at 15.48.29.png>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20231102/92706555/attachment-0002.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-qjsonobject.zip
Type: application/zip
Size: 3376 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20231102/92706555/attachment-0001.zip>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20231102/92706555/attachment-0003.htm>


More information about the Interest mailing list