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. Memoy leak using QtCharts
Forum Updated to NodeBB v4.3 + New Features

Memoy leak using QtCharts

Scheduled Pinned Locked Moved Unsolved General and Desktop
30 Posts 10 Posters 6.5k Views 5 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 aawawa

    @Christian-Ehrlicher Thank you. It's the first time I see *new in c++ what does it mean?

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #21

    @aawawa
    Hi
    Its a Dereference
    http://www.cplusplus.com/doc/tutorial/pointers/
    See section Dereference operator (*)

    1 Reply Last reply
    0
    • A Offline
      A Offline
      aawawa
      wrote on last edited by
      #22

      @mrjj yes... I understand... But I don't understand the location of the asterix (*). I am used for example to write

      int *a = new int;
      

      what does

      *new int
      

      means?

      mrjjM 1 Reply Last reply
      0
      • A aawawa

        @mrjj yes... I understand... But I don't understand the location of the asterix (*). I am used for example to write

        int *a = new int;
        

        what does

        *new int
        

        means?

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #23

        @aawawa
        Means
        value pointed to by ptr
        The actual value.

        int copy = *SomeIntPtr;
        that will copy the value to the copy var.
        if you did
        int copy = SomeIntPtr;
        you get the address of pointer into copy

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

          Ok, no memleak at all. You testcase is wrong / inaccurate.
          The problem with your testcase is that your eventloop is not (yet) running and that you also call it in an loop without a chance for the eventloop to do it's work. Since the internals of QLineSeries is cleaned up with a deferred delete it is not cleaned up until the eventloop is called (and after app.exec()). That's also the reason I thought the dtor is not called at all.

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

          1 Reply Last reply
          3
          • J Offline
            J Offline
            JosuGZ
            wrote on last edited by JosuGZ
            #25

            @Christian-Ehrlicher said in Memoy leak using QtCharts:

            Ok, no memleak at all. You testcase is wrong / inaccurate.
            The problem with your testcase is that your eventloop is not (yet) running and that you also call it in an loop without a chance for the eventloop to do it's work. Since the internals of QLineSeries is cleaned up with a deferred delete it is not cleaned up until the eventloop is called (and after app.exec()). That's also the reason I thought the dtor is not called at all.

            It seems to me that there are some memory leaks happening here.

            This code increases memory usage continuously:

            aSeries->remove(aSeries->points().size() - 1);
            aSeries->append(timestamp, mean);

            Bit this one does not:

            aSeries->replace(aSeries->points().size() - 1, timestamp, mean);

            I'm using Qt 5.11.2.

            JonBJ J.HilkJ 2 Replies Last reply
            0
            • J JosuGZ

              @Christian-Ehrlicher said in Memoy leak using QtCharts:

              Ok, no memleak at all. You testcase is wrong / inaccurate.
              The problem with your testcase is that your eventloop is not (yet) running and that you also call it in an loop without a chance for the eventloop to do it's work. Since the internals of QLineSeries is cleaned up with a deferred delete it is not cleaned up until the eventloop is called (and after app.exec()). That's also the reason I thought the dtor is not called at all.

              It seems to me that there are some memory leaks happening here.

              This code increases memory usage continuously:

              aSeries->remove(aSeries->points().size() - 1);
              aSeries->append(timestamp, mean);

              Bit this one does not:

              aSeries->replace(aSeries->points().size() - 1, timestamp, mean);

              I'm using Qt 5.11.2.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #26

              @JosuGZ
              In the last post 4 months ago made by @Christian-Ehrlicher, he explained that memory would only be recovered (and hence [hopefully] not permanently grow) when the OP allowed his code to reach the main event loop. I don't know how replace works, but remove surely will do a deferred delete. So in your example you need to be clear/show us how your code hits the event loop each time after do the remove/append?

              1 Reply Last reply
              1
              • J JosuGZ

                @Christian-Ehrlicher said in Memoy leak using QtCharts:

                Ok, no memleak at all. You testcase is wrong / inaccurate.
                The problem with your testcase is that your eventloop is not (yet) running and that you also call it in an loop without a chance for the eventloop to do it's work. Since the internals of QLineSeries is cleaned up with a deferred delete it is not cleaned up until the eventloop is called (and after app.exec()). That's also the reason I thought the dtor is not called at all.

                It seems to me that there are some memory leaks happening here.

                This code increases memory usage continuously:

                aSeries->remove(aSeries->points().size() - 1);
                aSeries->append(timestamp, mean);

                Bit this one does not:

                aSeries->replace(aSeries->points().size() - 1, timestamp, mean);

                I'm using Qt 5.11.2.

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #27

                hi @JosuGZ and welcome

                if you only monitor the memory your OS gives your application, then that is inaccurate.

                You have no influence over when the os decides that your freed memory will no longer be reserved for your application.

                Therefore
                remove -> append is memory is "freed" and a new allocation happens
                replace -> new data overwrites old data


                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.

                J 1 Reply Last reply
                0
                • J.HilkJ J.Hilk

                  hi @JosuGZ and welcome

                  if you only monitor the memory your OS gives your application, then that is inaccurate.

                  You have no influence over when the os decides that your freed memory will no longer be reserved for your application.

                  Therefore
                  remove -> append is memory is "freed" and a new allocation happens
                  replace -> new data overwrites old data

                  J Offline
                  J Offline
                  JosuGZ
                  wrote on last edited by
                  #28

                  @J.Hilk said in Memoy leak using QtCharts:

                  hi @JosuGZ and welcome

                  if you only monitor the memory your OS gives your application, then that is inaccurate.

                  You have no influence over when the os decides that your freed memory will no longer be reserved for your application.

                  Therefore
                  remove -> append is memory is "freed" and a new allocation happens
                  replace -> new data overwrites old data

                  An order of magnitude more RAM needed for a simple app is not an OS problem.

                  Two tests more replacing the offending line, one with small allocations:

                  char *test = (char *)malloc(10);
                  test[5] = 't'; // Touching memory
                  aSeries->replace(aSeries->points().size() - 1, ms, mean);
                  free(test);
                  

                  Another with bigger allocations:

                  char *test = (char *)malloc(10000);
                  test[5000] = 't'; // Touching memory
                  aSeries->replace(aSeries->points().size() - 1, ms, mean);
                  free(test);
                  

                  Both keep memory usage low as expected.

                  Even this keeps the memory constant:

                  QWidget *test = new QWidget;
                  aSeries->replace(aSeries->points().size() - 1, ms, mean);
                  test->deleteLater();
                  

                  Something is happening with this library and I'm not the only one with issues.

                  1 Reply Last reply
                  1
                  • T Offline
                    T Offline
                    thiagohd
                    wrote on last edited by
                    #29

                    Is this fixed in any way? I seem to have the same problem.

                    mrjjM 1 Reply Last reply
                    0
                    • T thiagohd

                      Is this fixed in any way? I seem to have the same problem.

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #30

                      @thiagohd
                      Hi
                      I dont think I bug report was ever created or it was further looked at.

                      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