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 is not full released after deleting all QPushButtons in QTApp

Memory is not full released after deleting all QPushButtons in QTApp

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 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.
  • A Offline
    A Offline
    asimfile
    wrote on last edited by
    #1

    i am creating a program containing QPushButtons, the Problem is when i am adding QPushButtons memory(RAM) increasing but when i deleted all added buttons memory is not fully releasing.

    void TempTest ::addSLOT()
    {
      li= new QList<QPushButton*>;
      for(int i=0;i<50000;i++)
       {
         QPushButton *p = new QPushButton;
         p->setText("sample");
         p->setFixedSize(100,100);
         li->append(p);
       }
    }
    void TempTest ::removeSLOT()
    {
      while(li->count())
       {
         QPushButton*p= li->at(0);
         li->removeAt(0);
         delete p;
       }
       delete li;
    }
    

    1.initialy memory is 2.0 mb

    2.after adding memory increased to 49.3 mb

    3.after deleting memory decreased to 4.1 mb

    there is 2.1 mb of RAM it never released

    1 Reply Last reply
    0
    • BjornWB Offline
      BjornWB Offline
      BjornW
      wrote on last edited by
      #2

      How do you check memory consumption? Afaik, all memory may not be returned immediately to the OS.

      If you run your example multiple times, do you see a steady increase by 2 MB for each iteration?

      A 1 Reply Last reply
      0
      • BjornWB BjornW

        How do you check memory consumption? Afaik, all memory may not be returned immediately to the OS.

        If you run your example multiple times, do you see a steady increase by 2 MB for each iteration?

        A Offline
        A Offline
        asimfile
        wrote on last edited by
        #3

        thanks for replying @BjornW
        further if i repeat same process -
        again add and delete Buttons - 4.4 mb
        again add and delete Buttons - 4.9 mb
        again add and delete Buttons - 4.6 mb
        again add and delete Buttons - 4.4 mb
        again add and delete Buttons - 5.4 mb
        again add and delete Buttons - 4.9 mb
        again add and delete Buttons - 4.6 mb

        kshegunovK 1 Reply Last reply
        0
        • A asimfile

          thanks for replying @BjornW
          further if i repeat same process -
          again add and delete Buttons - 4.4 mb
          again add and delete Buttons - 4.9 mb
          again add and delete Buttons - 4.6 mb
          again add and delete Buttons - 4.4 mb
          again add and delete Buttons - 5.4 mb
          again add and delete Buttons - 4.9 mb
          again add and delete Buttons - 4.6 mb

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          See my answer here.

          Read and abide by the Qt Code of Conduct

          A 1 Reply Last reply
          1
          • kshegunovK kshegunov

            See my answer here.

            A Offline
            A Offline
            asimfile
            wrote on last edited by
            #5

            @kshegunov thanks for reply , i have read your link and it seems OS is resposible for memory loss.

            kshegunovK 1 Reply Last reply
            0
            • A asimfile

              @kshegunov thanks for reply , i have read your link and it seems OS is resposible for memory loss.

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by
              #6

              @asimfile said in Memory is not full released after deleting all QPushButtons in QTApp:

              it seems OS is resposible for memory loss

              You misunderstood. The OS is responsible for memory management. C++ is a stack based language (following ASM's push and pop), everything you allocate on the heap is managed by the OS's heap manager - that's its purpose (small wonder the heap allocation in C is a function). In any case, if you need to make sure you don't leak things, just use a code analyzer.

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply
              1

              • Login

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