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. QT5 application crashed after running for some long time.....
QtWS25 Last Chance

QT5 application crashed after running for some long time.....

Scheduled Pinned Locked Moved Solved General and Desktop
crashbad allocationmemoryexception
18 Posts 7 Posters 7.5k 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.
  • M Offline
    M Offline
    mpergand
    wrote on 24 Jun 2019, 18:34 last edited by mpergand
    #9

    I've experiencing same issue on Mac, I solved it by doing two things:

    • put a breakpoint according to the exception, here std::bad_alloc::bad_alloc()
    • add _GLIBCXX_DEBUG=1 to the Buid environment variables (unless the stack trace is meaningless)

    Hope it helps.

    1 Reply Last reply
    3
    • A aha_1980
      24 Jun 2019, 17:14

      @VikramSamy said in QT5 application crashed after running for some long time.....:

      how do set the debugger to break during the std:bad_alloc ??signal???

      Usually you just start the program in the debugger and on an exception, the debugger jumps in.

      As @fcarney suggested, you can try to run your app under another operating system, or on Windows, you can run it under MinGW instead MSVC, e.g.

      Doing so usually gives you different compiler warnings / errors and sometimes different runtime behavior.

      It's also worth to use the tools heob and valgrind, as @fcarney said. these are good in finding memory leaks.

      V Offline
      V Offline
      VikramSamy
      wrote on 25 Jun 2019, 02:18 last edited by VikramSamy
      #10

      @aha_1980 said in QT5 application crashed after running for some long time.....:

      Usually you just start the program in the debugger and on an exception, the debugger jumps in.

      Yup this what i expected, but the debugger didnt jump in.... so did i miss any kind of settings or configurations in the debugger??.

      @mpergand said in QT5 application crashed after running for some long time.....:

      I've experiencing same issue on Mac, I solved it by doing two things:

      • put a breakpoint according to the exception, here std::bad_alloc::bad_alloc()
      • add _GLIBCXX_DEBUG=1 to the Buid environment variables (unless the stack trace is meaningless)

      Hope it helps.

      HI @mpergand , what u mean by "put a breakpoint according to the exception, here std::bad_alloc::bad_alloc()", and where do i need to put the breakpoint, u mean i can tell in 'debugger configurations' to break the at the exception??? care for more details about what u saying??

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mpergand
        wrote on 25 Jun 2019, 13:11 last edited by mpergand
        #11

        @mpergand said in QT5 application crashed after running for some long time.....:

        std::bad_alloc::bad_alloc()

        Please read this page:
        https://doc.qt.io/qtcreator/creator-debug-mode.html
        You can have a test with std::out_of_range
        In the breakpoint panel, right-clic->add breakpoint,
        for type choose : C++ exception is thrown
        for condition write: std::out_of_range

        If you execute this code in debug mode:

        std::vector<int> v;
        v.at(0);
        

        The prg should stop and the stack trace panel shows the line where the exception occurs.

        A 1 Reply Last reply 25 Jun 2019, 13:29
        7
        • M mpergand
          25 Jun 2019, 13:11

          @mpergand said in QT5 application crashed after running for some long time.....:

          std::bad_alloc::bad_alloc()

          Please read this page:
          https://doc.qt.io/qtcreator/creator-debug-mode.html
          You can have a test with std::out_of_range
          In the breakpoint panel, right-clic->add breakpoint,
          for type choose : C++ exception is thrown
          for condition write: std::out_of_range

          If you execute this code in debug mode:

          std::vector<int> v;
          v.at(0);
          

          The prg should stop and the stack trace panel shows the line where the exception occurs.

          A Offline
          A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on 25 Jun 2019, 13:29 last edited by
          #12

          @mpergand Awesome! I didn't know you can catch these. Thanks for your explanation.

          Qt has to stay free or it will die.

          1 Reply Last reply
          0
          • F fcarney
            24 Jun 2019, 16:03

            You can run heob as a memory analyzer in Windows 10. It is discussed in the Qt docs. However, heob and valgrind find different things I have noticed. So, if possible, it might be valuable to run a virtual machine with Linux on it to test your code with valgrind. That assumes it can run in Linux though, so may not be applicable. Our apps are compile-able in both linux and windows. valgrind for instance, found alignment errors in unions due to compiler change from 32 bit to 64 bit. Not sure if heob could find that or not.

            S Offline
            S Offline
            ssbssa
            wrote on 30 Jun 2019, 12:23 last edited by
            #13

            @fcarney said in QT5 application crashed after running for some long time.....:

            valgrind for instance, found alignment errors in unions due to compiler change from 32 bit to 64 bit. Not sure if heob could find that or not.

            No, heob can't do that.
            It's mainly for heap related problems, like memory leaks and heap overflows.

            1 Reply Last reply
            1
            • F fcarney
              24 Jun 2019, 16:03

              You can run heob as a memory analyzer in Windows 10. It is discussed in the Qt docs. However, heob and valgrind find different things I have noticed. So, if possible, it might be valuable to run a virtual machine with Linux on it to test your code with valgrind. That assumes it can run in Linux though, so may not be applicable. Our apps are compile-able in both linux and windows. valgrind for instance, found alignment errors in unions due to compiler change from 32 bit to 64 bit. Not sure if heob could find that or not.

              V Offline
              V Offline
              VikramSamy
              wrote on 2 Jul 2019, 02:08 last edited by
              #14

              @fcarney said in QT5 application crashed after running for some long time.....:

              You can run heob as a memory analyzer in Windows 10. It is discussed in the Qt docs. However, heob and valgrind find different things I have noticed. So, if possible, it might be valuable to run a virtual machine with Linux on it to test your code with valgrind. That assumes it can run in Linux though, so may not be applicable. Our apps are compile-able in both linux and windows. valgrind for instance, found alignment errors in unions due to compiler change from 32 bit to 64 bit. Not sure if heob could find that or not.

              The issue: -the application memory increase once the application runs, in just small bytes but it continually increasing all the way until crash.

              @fcarney i run heob and tried.... i just use the basic setting in the QT documentation related to heob, and i got more than 1650 issue, but anyway im only looking into any issue related to the line number of my code only, A example issues is as below and mostly the issues are referring the same function block, after my application crash i check the debug panel contained messages as below:-

              0_1562030120509_heob_results.png

              the no 5,6 and 10 are actually code written by me, so i need to check this codes for some memory leak right??? so basically heob will just tell us which line of code is leaking memory and i need rewrite the function in some way that not leak memory, that should be the target, right??

              So the reason for post is, how do we actually analyze heob data??? and use it to check the code??? because it show so many issue 1650, and so many lines of code, i think i just need ignored the other line of codes not written by me and just check on all the lines of codes belong to me,and mostly its the same function block again, below is one of the example section of code:-

              //your code here
              void SUB_EVENT_PANEL::Change_Chain_Track_Status_Eventviewer(LED_STATUS led_status)
              {
              
                  STATUS_BIT_TYPE status_mask;
                  STATUS_BIT_TYPE  i; // i need be static,???no need
              
                  status_mask =1; //0x01
                     
                  //initialize the status messages
                  //m_leak                                           
              TableMessages<<tr("HEALTHY")<<("ATS ALARMED!!")<<tr("SYSTEM HEALTHY")<<tr("IN BYPASS 
               MODE")<<tr("LCP/PCP TAMPERED")<<tr("INTRUSION TRIGGERED")<<tr("CABLE FAULT")<<tr("FUTURE NOT USED...")<<tr("ACKNOWLEDGE")<<tr("RESET...")<<tr("A ON...")<<tr("B ON...")<<tr("PLC COMM OK");
               
              TableMessagesNOT<<tr("ATS ALARMED!!")<<tr("ATS HEALTHY!!")<<("SYSTEM UNHEALTHY")<<tr("IN NORMAL MODE")<<tr("LCP/PCP SECURE")<<tr("INTRUSION CLEARED")<<tr("CABLE OK")<<tr("FUTURE NOT USED...")<<tr("N/A")<<tr("N/A")<<tr("A OFF...")<<tr("B OFF...")<<tr("PLC COMM LOSS");
              
               ........ continues other code  }
                     
              

              so one of issue the heob points to this TableMessages which i declared at the header as below:

              //your code here
              private:
               QStringList TableMessages;
               QStringList TableMessagesNOT;
              

              and the above function is called everytime a tcpip packet is received and parsed, a packet is send every 0.02 by a PLC client, and by using a for loop i check if there any event (any bit is toggled) and if yes write to the HMI table as below, part of the coding:-

              //your code here
               case 2:qDebug() <<"caseN_E 2-system healthy";
                  if (Data_Process::Get_Status_Bit(led_status.button_statusR, System_Health_STATUS_BIT))
                             {
                              TableWrite(i);
                             }
                 if (!(Data_Process::Get_Status_Bit(led_status.button_statusR, System_Health_STATUS_BIT)))
                             {
                              TableWriteNOT(i);
                             }
                             break;
              

              so according to heob most of my data leak are coming from this function,so the memory allocated for this QStringList TableMessages; is the problem as heob point to this exact line, and few others.... is this because i allocated the memory without using NEW keyword??? any ideas,tips,hints??

              J 1 Reply Last reply 2 Jul 2019, 05:58
              0
              • V VikramSamy
                2 Jul 2019, 02:08

                @fcarney said in QT5 application crashed after running for some long time.....:

                You can run heob as a memory analyzer in Windows 10. It is discussed in the Qt docs. However, heob and valgrind find different things I have noticed. So, if possible, it might be valuable to run a virtual machine with Linux on it to test your code with valgrind. That assumes it can run in Linux though, so may not be applicable. Our apps are compile-able in both linux and windows. valgrind for instance, found alignment errors in unions due to compiler change from 32 bit to 64 bit. Not sure if heob could find that or not.

                The issue: -the application memory increase once the application runs, in just small bytes but it continually increasing all the way until crash.

                @fcarney i run heob and tried.... i just use the basic setting in the QT documentation related to heob, and i got more than 1650 issue, but anyway im only looking into any issue related to the line number of my code only, A example issues is as below and mostly the issues are referring the same function block, after my application crash i check the debug panel contained messages as below:-

                0_1562030120509_heob_results.png

                the no 5,6 and 10 are actually code written by me, so i need to check this codes for some memory leak right??? so basically heob will just tell us which line of code is leaking memory and i need rewrite the function in some way that not leak memory, that should be the target, right??

                So the reason for post is, how do we actually analyze heob data??? and use it to check the code??? because it show so many issue 1650, and so many lines of code, i think i just need ignored the other line of codes not written by me and just check on all the lines of codes belong to me,and mostly its the same function block again, below is one of the example section of code:-

                //your code here
                void SUB_EVENT_PANEL::Change_Chain_Track_Status_Eventviewer(LED_STATUS led_status)
                {
                
                    STATUS_BIT_TYPE status_mask;
                    STATUS_BIT_TYPE  i; // i need be static,???no need
                
                    status_mask =1; //0x01
                       
                    //initialize the status messages
                    //m_leak                                           
                TableMessages<<tr("HEALTHY")<<("ATS ALARMED!!")<<tr("SYSTEM HEALTHY")<<tr("IN BYPASS 
                 MODE")<<tr("LCP/PCP TAMPERED")<<tr("INTRUSION TRIGGERED")<<tr("CABLE FAULT")<<tr("FUTURE NOT USED...")<<tr("ACKNOWLEDGE")<<tr("RESET...")<<tr("A ON...")<<tr("B ON...")<<tr("PLC COMM OK");
                 
                TableMessagesNOT<<tr("ATS ALARMED!!")<<tr("ATS HEALTHY!!")<<("SYSTEM UNHEALTHY")<<tr("IN NORMAL MODE")<<tr("LCP/PCP SECURE")<<tr("INTRUSION CLEARED")<<tr("CABLE OK")<<tr("FUTURE NOT USED...")<<tr("N/A")<<tr("N/A")<<tr("A OFF...")<<tr("B OFF...")<<tr("PLC COMM LOSS");
                
                 ........ continues other code  }
                       
                

                so one of issue the heob points to this TableMessages which i declared at the header as below:

                //your code here
                private:
                 QStringList TableMessages;
                 QStringList TableMessagesNOT;
                

                and the above function is called everytime a tcpip packet is received and parsed, a packet is send every 0.02 by a PLC client, and by using a for loop i check if there any event (any bit is toggled) and if yes write to the HMI table as below, part of the coding:-

                //your code here
                 case 2:qDebug() <<"caseN_E 2-system healthy";
                    if (Data_Process::Get_Status_Bit(led_status.button_statusR, System_Health_STATUS_BIT))
                               {
                                TableWrite(i);
                               }
                   if (!(Data_Process::Get_Status_Bit(led_status.button_statusR, System_Health_STATUS_BIT)))
                               {
                                TableWriteNOT(i);
                               }
                               break;
                

                so according to heob most of my data leak are coming from this function,so the memory allocated for this QStringList TableMessages; is the problem as heob point to this exact line, and few others.... is this because i allocated the memory without using NEW keyword??? any ideas,tips,hints??

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 2 Jul 2019, 05:58 last edited by
                #15

                @VikramSamy Do you remove values from TableMessages and TableMessagesNOT somewhere?

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                5
                • F Offline
                  F Offline
                  fcarney
                  wrote on 2 Jul 2019, 14:56 last edited by
                  #16

                  @VikramSamy said in QT5 application crashed after running for some long time.....:

                  TableMessages<<tr("HEALTHY")<<("ATS ALARMED!!")<<tr("SYSTEM HEALTHY")<<tr("IN BYPASS
                  MODE")<<tr("LCP/PCP TAMPERED")<<tr("INTRUSION TRIGGERED")<<tr("CABLE FAULT")<<tr("FUTURE NOT USED...")<<tr("ACKNOWLEDGE")<<tr("RESET...")<<tr("A ON...")<<tr("B ON...")<<tr("PLC COMM OK");

                  TableMessagesNOT<<tr("ATS ALARMED!!")<<tr("ATS HEALTHY!!")<<("SYSTEM UNHEALTHY")<<tr("IN NORMAL MODE")<<tr("LCP/PCP SECURE")<<tr("INTRUSION CLEARED")<<tr("CABLE OK")<<tr("FUTURE NOT USED...")<<tr("N/A")<<tr("N/A")<<tr("A OFF...")<<tr("B OFF...")<<tr("PLC COMM LOSS");

                  If you are adding to these lists and never removing anything, then yes you are consuming more and more memory every time this function is called. If you need to rebuild these lists on each run, then clear them out before you add more to them.

                  C++ is a perfectly valid school of magic.

                  1 Reply Last reply
                  5
                  • V Offline
                    V Offline
                    VikramSamy
                    wrote on 3 Jul 2019, 02:48 last edited by VikramSamy 7 Mar 2019, 02:56
                    #17

                    @fcarney @jsulm

                    Hi yup i dint remove the QStringList anywhere, as i thought it will be automatically destroyed when it gets out of the function, what i didn't realize is that i created the QStringlist at the headers file and initialized it in the functions ,as per that it will allocated in the heap/dynamically and will be continuously allocated new memory each time the function is called..ok i got it, ....

                    now what the best thing to do, how do i remove it?? is it better to remained in this way, allocated in the heap memory and removing it when not used?? so i need use the removeall or clearall to deallocated memory?? care for a correct example of deleting the Qstringlist properly??

                    Anyway after some reading,i just modify my code to allocated the QstringList inside the functions itself (like local variable),
                    so now memory is allocated in the stack and it will be destroyed when it exit the functions (out of scope) and i tested the code and the memory does not increase as previously ,so it is better now .

                    the new code is as below:

                    void SUB_EVENT_PANEL::Change_Chain_Track_Status_Eventviewer(LED_STATUS led_status)
                    {
                       QStringList TableMessagesNOT;  // now i declared here
                      TableMessagesNOT<<tr("ALARMED!!")  // and initialize here
                    
                        
                    } //so will be deleted after go out of scope, and memory released.
                    

                    so my question which is the better, use as my original code and delete the Qstringlist somewhere, or create the QStringlist in the stack and let it get destroyed by itself after getting out of scope as above ??

                    J 1 Reply Last reply 3 Jul 2019, 04:21
                    0
                    • V VikramSamy
                      3 Jul 2019, 02:48

                      @fcarney @jsulm

                      Hi yup i dint remove the QStringList anywhere, as i thought it will be automatically destroyed when it gets out of the function, what i didn't realize is that i created the QStringlist at the headers file and initialized it in the functions ,as per that it will allocated in the heap/dynamically and will be continuously allocated new memory each time the function is called..ok i got it, ....

                      now what the best thing to do, how do i remove it?? is it better to remained in this way, allocated in the heap memory and removing it when not used?? so i need use the removeall or clearall to deallocated memory?? care for a correct example of deleting the Qstringlist properly??

                      Anyway after some reading,i just modify my code to allocated the QstringList inside the functions itself (like local variable),
                      so now memory is allocated in the stack and it will be destroyed when it exit the functions (out of scope) and i tested the code and the memory does not increase as previously ,so it is better now .

                      the new code is as below:

                      void SUB_EVENT_PANEL::Change_Chain_Track_Status_Eventviewer(LED_STATUS led_status)
                      {
                         QStringList TableMessagesNOT;  // now i declared here
                        TableMessagesNOT<<tr("ALARMED!!")  // and initialize here
                      
                          
                      } //so will be deleted after go out of scope, and memory released.
                      

                      so my question which is the better, use as my original code and delete the Qstringlist somewhere, or create the QStringlist in the stack and let it get destroyed by itself after getting out of scope as above ??

                      J Offline
                      J Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on 3 Jul 2019, 04:21 last edited by
                      #18

                      @VikramSamy said in QT5 application crashed after running for some long time.....:

                      so my question which is the better, use as my original code and delete the Qstringlist somewhere, or create the QStringlist in the stack and let it get destroyed by itself after getting out of scope as above ??

                      There is no generic answer to this question as it simply depends on the use case. If you only need this list in that method then you simply allocate it as local variable. Having it as member variable in the class is only needed if you need the list at several places in your class.
                      By the way this is not heap allocation:

                      private:
                       QStringList TableMessages;
                       QStringList TableMessagesNOT;
                      

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      1

                      18/18

                      3 Jul 2019, 04:21

                      • Login

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