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. Possible memory leak in QVariant::toString().split()
Forum Updated to NodeBB v4.3 + New Features

Possible memory leak in QVariant::toString().split()

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 733 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.
  • I Offline
    I Offline
    ivanov.ivan
    wrote on last edited by ivanov.ivan
    #1
    QVariantMap map;
    map["key"]=QString("val1,val2,val3,val4,val5,val6,val7,val8,val9,val0");
    
    // memory increase in loop and not release
    for (int i =0; i < 100000; i++)
    {
       QStringList list = map["key"].toString().split(",");
       QStringList sameList = (*static_cast<QString*>(map["key"].constData())).split(",");
       //qDebug() << i << list.size() << sameList.size();
    }
    

    Qt 6.5.3 build static from source cross by arm-linux-gnueabihf-gcc-9.5, execute with warning:
    Detected locale "C" with character encoding "ANSI_X3.4-1968", which is not UTF-8."

    1 Reply Last reply
    0
    • M Offline
      M Offline
      miraal
      wrote on last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      0
      • J.HilkJ Online
        J.HilkJ Online
        J.Hilk
        Moderators
        wrote on last edited by J.Hilk
        #3

        Do not concern yourself with (very unlikely) Qt memory leak issues when you do abominations like this:

        (*static_cast<QString*>(map["key"].constData())).split(",");
        

        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        I 1 Reply Last reply
        2
        • J.HilkJ J.Hilk

          Do not concern yourself with (very unlikely) Qt memory leak issues when you do abominations like this:

          (*static_cast<QString*>(map["key"].constData())).split(",");
          
          I Offline
          I Offline
          ivanov.ivan
          wrote on last edited by ivanov.ivan
          #4

          @J-Hilk you can comment this line, memory increase anyway, so i present 2 variants with same result

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            How do you know that there is a leak? Use a proper profiler.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            I 1 Reply Last reply
            1
            • Christian EhrlicherC Christian Ehrlicher

              How do you know that there is a leak? Use a proper profiler.

              I Offline
              I Offline
              ivanov.ivan
              wrote on last edited by ivanov.ivan
              #6

              @Christian-Ehrlicher I wraped functions free & malloc, as: __wrap_malloc & __wrap_free. Then I start QProcess with ssh command to host to get backtrace via gdb-multiarch in __wrap_malloc to search code location where allocated mem not released.

              1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Use a proper profiler for instead some self made stuff. There is no memory leak.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                I 1 Reply Last reply
                1
                • Christian EhrlicherC Christian Ehrlicher

                  Use a proper profiler for instead some self made stuff. There is no memory leak.

                  I Offline
                  I Offline
                  ivanov.ivan
                  wrote on last edited by ivanov.ivan
                  #8

                  @Christian-Ehrlicher Does exist a proper profiler for embedded arm?

                  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