Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Cant free memory used by QList
Qt 6.11 is out! See what's new in the release blog

Cant free memory used by QList

Scheduled Pinned Locked Moved Mobile and Embedded
8 Posts 5 Posters 7.1k 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.
  • G Offline
    G Offline
    gandiii
    wrote on last edited by
    #1

    Hi,

    I am using two QLists in my dataobject, one with QString and the other with int.
    If I make some instances of my dataobject, delete them and create them again, the
    memory is increasing and so on.
    I tried delete, qDeleteAll, clear but nothing worked.
    Is there a way or should I use an array?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lycis
      wrote on last edited by
      #2

      Maybe you could provide us with some code snippets? It's hard to tell why your memory is leaking - maybe you are using pointers to memory areas that are not deleted?

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gandiii
        wrote on last edited by
        #3

        ok.

        thats my dataobject
        @
        class dataobj {
        QList<QString> Names;
        QList<int> Values;
        }@

        I use the code that way:
        @
        QList<dataobj*>tmp;
        for(int i = 0; i<MAX_DATA;i++){
        tmp.append(new dataobj());
        tmp.at(i)->Names.append("test1");
        tmp.at(i)->Names.append("test2");
        tmp.at(i)->Values.append(2);
        tmp.at(i)->Values.append(5);
        }@

        in the destructor I delete every instance of the dataobject:
        @
        for(int i = 0; i<MAX_DATA;i++){
        delete tmp.at(i);
        }
        tmp.clear();
        @

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          Have a look at "this thread":https://qt-project.org/forums/viewthread/13816/. I think the solutions sugested there can be applied to your case as well.

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            How do you measure memory usage?

            1 Reply Last reply
            0
            • G Offline
              G Offline
              gandiii
              wrote on last edited by
              #6

              I did this with "top".
              But yesterday I have rebuilt my builtroot and now
              its working. Its really strange because the settings are the same.

              1 Reply Last reply
              0
              • JohanSoloJ Offline
                JohanSoloJ Offline
                JohanSolo
                wrote on last edited by
                #7

                top is not showing the memory presently used by a program: it shows the maximum amount of memory used by a program (or process). Part of the "used" memory may be freed but still "assigned" to the program in case it needs some more. The memory seen with top won't decrease unless some other program needs some more and cannot find any free memory.

                I've also been tricked by this behaviour ;-)

                `They did not know it was impossible, so they did it.'
                -- Mark Twain

                1 Reply Last reply
                0
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #8

                  Indeed, top isn't suitable for this. I would suggest using valgrind or something similar to check wether you actually do have a memory leak. The wiki page "Tools for Profiling and Memory Checking":/wiki/Profiling-and-Memory-Checking-Tools contains a list of suitable tools for various platforms.

                  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