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. Qt6 C++ memory leak seemingly from main window
QtWS25 Last Chance

Qt6 C++ memory leak seemingly from main window

Scheduled Pinned Locked Moved Solved General and Desktop
qt6memory leak
3 Posts 2 Posters 418 Views
  • 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.
  • D Offline
    D Offline
    Deneguil
    wrote on 23 Nov 2024, 10:49 last edited by
    #1

    Hello,

    I am writing a rather small Qt6 application in C++. I have a little experience with Qt in Python and I chose to use the QtDesigner tool to make the UI (I don't know if that's relevant but maybe). I just ran my program through Valgrind and it reported 3 KB of memory leaked (with 377 KB "still reachable" but after looking it up I can ignore those). At first I thought the issue might come from my custom graphics view, so I commented it out to try and isolate the problem but it still pops up.

    The biggest, an only "definitely lost" block point back to the initialization of the QGuiApplication which is why I think it might come from the main window itself.

    c1ab0093-843a-4923-9097-9d84fe93cb0d-image.png

    With the other 2 blocks coming from QGuiApplicationPrivate::createEventDispatcher and QWindowPrivate::create respectively.

    Now I am a bit confused about where I'm going from because as far as I'm aware my application setup doesn't allocate memory on the heap so I don't know what I should free

    // main.cpp
    int main(int argc, char* argv[]) {
    
        QApplication a(argc, argv);
        AutomatLab w;
    
        w.show();
    
        return a.exec();
    }
    
    // AutomatLab.hpp
    class AutomatLab : public QMainWindow {
        Q_OBJECT
    
    private:
        Ui::AutomatLab ui;
        //GraphicView gv;
    
    public:
        AutomatLab();
        ~AutomatLab();
    
    };
    
    // AutomatLab.cpp
    AutomatLab::AutomatLab() { 
        ui.setupUi(this);
        //ui.GraphView->layout()->addWidget(&gv);
        this->show();
    }
    
    AutomatLab::~AutomatLab() {}
    

    I am using CMake to autogenerate the UI files into headers during compilation.

    Any help is appreciated, this isn't a heavy application so memory leaks wouldn't be that serious but I would rather understand what I'm doing to not get into bad habits.

    Thank you

    P 1 Reply Last reply 23 Nov 2024, 12:09
    0
    • D Deneguil
      23 Nov 2024, 10:49

      Hello,

      I am writing a rather small Qt6 application in C++. I have a little experience with Qt in Python and I chose to use the QtDesigner tool to make the UI (I don't know if that's relevant but maybe). I just ran my program through Valgrind and it reported 3 KB of memory leaked (with 377 KB "still reachable" but after looking it up I can ignore those). At first I thought the issue might come from my custom graphics view, so I commented it out to try and isolate the problem but it still pops up.

      The biggest, an only "definitely lost" block point back to the initialization of the QGuiApplication which is why I think it might come from the main window itself.

      c1ab0093-843a-4923-9097-9d84fe93cb0d-image.png

      With the other 2 blocks coming from QGuiApplicationPrivate::createEventDispatcher and QWindowPrivate::create respectively.

      Now I am a bit confused about where I'm going from because as far as I'm aware my application setup doesn't allocate memory on the heap so I don't know what I should free

      // main.cpp
      int main(int argc, char* argv[]) {
      
          QApplication a(argc, argv);
          AutomatLab w;
      
          w.show();
      
          return a.exec();
      }
      
      // AutomatLab.hpp
      class AutomatLab : public QMainWindow {
          Q_OBJECT
      
      private:
          Ui::AutomatLab ui;
          //GraphicView gv;
      
      public:
          AutomatLab();
          ~AutomatLab();
      
      };
      
      // AutomatLab.cpp
      AutomatLab::AutomatLab() { 
          ui.setupUi(this);
          //ui.GraphView->layout()->addWidget(&gv);
          this->show();
      }
      
      AutomatLab::~AutomatLab() {}
      

      I am using CMake to autogenerate the UI files into headers during compilation.

      Any help is appreciated, this isn't a heavy application so memory leaks wouldn't be that serious but I would rather understand what I'm doing to not get into bad habits.

      Thank you

      P Offline
      P Offline
      Pl45m4
      wrote on 23 Nov 2024, 12:09 last edited by
      #2

      @Deneguil

      The code you show doesn't have any obvious memory leaks...
      The ...Private classes are part of Qt's internals and there are also no leaks, for sure.

      Sometimes Valgrind or other tools report false positives because they can't analyze the object relations properly.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      D 1 Reply Last reply 24 Nov 2024, 12:51
      2
      • P Pl45m4
        23 Nov 2024, 12:09

        @Deneguil

        The code you show doesn't have any obvious memory leaks...
        The ...Private classes are part of Qt's internals and there are also no leaks, for sure.

        Sometimes Valgrind or other tools report false positives because they can't analyze the object relations properly.

        D Offline
        D Offline
        Deneguil
        wrote on 24 Nov 2024, 12:51 last edited by
        #3

        @Pl45m4

        Thank you for your feedback, I'm fairly experienced with plain C++ but not very with Qt or using Valgrind with external dependencies so I was a bit confused about what was happening.

        I'll keep that in mind in the future!

        1 Reply Last reply
        0
        • D Deneguil has marked this topic as solved on 24 Nov 2024, 12:51

        3/3

        24 Nov 2024, 12:51

        • Login

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