Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Memory leak in QJsonObject::insert? Bug?
Forum Updated to NodeBB v4.3 + New Features

Memory leak in QJsonObject::insert? Bug?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    syfy323
    wrote on last edited by
    #1

    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;
    serviceJObject.insert("keyName",QJsonValue(QString("keyValue")));
    *jsonObject = serviceJObject;@

    This is stable at the moment.

    Doing this results in memory leaks:
    @jsonObject->insert("keyName",QJsonValue(QString("keyValue")));@

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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      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 ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        syfy323
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved