Important: Please read the Qt Code of Conduct -

Memory leak in QJsonObject::insert? Bug?

  • In my application I am using a QJsonObject* which will be filled with key + values.
    This method is called several times, each time using the insert-method with the same key but with a new value.
    The docs state that, if the key already exists, that the value gets overwritten (this is what I want).

    The last two days I was searching for the memory leak (I have several big QJsonDocuments).
    I got it working by uglifying it:

    @QJsonObject serviceJObject;
    *jsonObject = serviceJObject;@

    This is stable at the moment.

    Doing this results in memory leaks:

    Can someone test this? I got this problem several times resulting in memory sizes beyond 250MB where it normaly used 3.5MB.

  • Lifetime Qt Champion


    What version of Qt and OS are you using ?

    Just tested creating a new QJsonObject on the heap and inserting in a loop and no leak.

    Are you sure you are not e.g. maybe re-creating jsonObject somewhere thus loosing an object each time ?

  • I am working on Win 8.1 + Qt 5.2.1 using MinGW.

    The code posted above is the only code I am using.
    I am just pulling (getter method) the pointer from another class to get its content. No delete or something.

Log in to reply