Memory is not full released after deleting all QPushButtons in QTApp



  • 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



  • 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?



  • 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


  • Qt Champions 2016

    See my answer here.



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


  • Qt Champions 2016

    @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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.