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. QTimer handle leak from inside Qt?
Forum Updated to NodeBB v4.3 + New Features

QTimer handle leak from inside Qt?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 1.2k 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.
  • M Offline
    M Offline
    magnus.ni
    wrote on last edited by
    #1

    Hi. The software I'm working on (using Qt 5.5) crashed recently and I cannot figure out why. The latest log output suggested the event loop was under a lot of stress but running.

    The error message from the main thread "QEventDispatcherWin32::registerTimer: Failed to create a timer (The current process has used all of its system allowance of handles for Window Manager objects.)" is printed every 500usec to the log handler. It is unknown where it began, I cannot reproduce it or know how it started.

    The user after about 20 minutes called abort on the Windows message "window is not responding".

    Something has begun leaking handles while creating timer object probably as fast as possible (the 500usec delta is probably the slowdown due to the error message log handler call). I examined every "new QTimer" and every "QTimer::singleShot" in the source code: nowhere is this created in a loop, in a recursion or in code called repeatedly like this.

    This is probably a though guess but are there any qt constructs which implicitly create QTimer object / handles which might help identify what's get called here?

    I first suggested this might be for some reason too many C++11 calls to QThreadLoop using QtConcurrent::run ...but only handles with the maximum amount of active worker threads are actually consumed.

    Any insight on what might be wrong here? Thank you!

    K JonBJ 2 Replies Last reply
    0
    • M magnus.ni

      Hi. The software I'm working on (using Qt 5.5) crashed recently and I cannot figure out why. The latest log output suggested the event loop was under a lot of stress but running.

      The error message from the main thread "QEventDispatcherWin32::registerTimer: Failed to create a timer (The current process has used all of its system allowance of handles for Window Manager objects.)" is printed every 500usec to the log handler. It is unknown where it began, I cannot reproduce it or know how it started.

      The user after about 20 minutes called abort on the Windows message "window is not responding".

      Something has begun leaking handles while creating timer object probably as fast as possible (the 500usec delta is probably the slowdown due to the error message log handler call). I examined every "new QTimer" and every "QTimer::singleShot" in the source code: nowhere is this created in a loop, in a recursion or in code called repeatedly like this.

      This is probably a though guess but are there any qt constructs which implicitly create QTimer object / handles which might help identify what's get called here?

      I first suggested this might be for some reason too many C++11 calls to QThreadLoop using QtConcurrent::run ...but only handles with the maximum amount of active worker threads are actually consumed.

      Any insight on what might be wrong here? Thank you!

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @magnus.ni

      Hi and welcome to devnet forum

      This is merely a user's forum. Your question is probably better suited in the developer's mailing list.

      Also your Qt version is fairly old. Can't you update to more recent versions? We have already version 5.12.

      Vote the answer(s) that helped you to solve your issue(s)

      M 1 Reply Last reply
      3
      • M magnus.ni

        Hi. The software I'm working on (using Qt 5.5) crashed recently and I cannot figure out why. The latest log output suggested the event loop was under a lot of stress but running.

        The error message from the main thread "QEventDispatcherWin32::registerTimer: Failed to create a timer (The current process has used all of its system allowance of handles for Window Manager objects.)" is printed every 500usec to the log handler. It is unknown where it began, I cannot reproduce it or know how it started.

        The user after about 20 minutes called abort on the Windows message "window is not responding".

        Something has begun leaking handles while creating timer object probably as fast as possible (the 500usec delta is probably the slowdown due to the error message log handler call). I examined every "new QTimer" and every "QTimer::singleShot" in the source code: nowhere is this created in a loop, in a recursion or in code called repeatedly like this.

        This is probably a though guess but are there any qt constructs which implicitly create QTimer object / handles which might help identify what's get called here?

        I first suggested this might be for some reason too many C++11 calls to QThreadLoop using QtConcurrent::run ...but only handles with the maximum amount of active worker threads are actually consumed.

        Any insight on what might be wrong here? Thank you!

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

        @magnus.ni
        There seem to be two possibilities:

        • Despite what you say, your code is somehow creating many timers (e.g. via slots). Are you freeing the QTimers when you're done with them? If you are only using QTimer::singleShot, do you need those instances, could you just use the static version?

        • As e.g. @SGaist said in https://forum.qt.io/topic/54438/solved-qt-5-4-1-qtimer-using-up-all-handles-for-window-manager-objects, it may not be the QTimer itself which is being repeatedly created. The error message could just indicate that you are using up too many Windows handles in general, e.g. from widgets or whatever else in your code. (In that link it turned out the OP was creating multiple QNetworkAccessManagers --- not saying that's you, but could be anything.)

        M 1 Reply Last reply
        5
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          If the process is running you can get the details of handles which are open. Either use process explorer or sone other tool to see the handle details. It is possible that timer error just a manifestation of some other issue.

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          2
          • K koahnig

            @magnus.ni

            Hi and welcome to devnet forum

            This is merely a user's forum. Your question is probably better suited in the developer's mailing list.

            Also your Qt version is fairly old. Can't you update to more recent versions? We have already version 5.12.

            M Offline
            M Offline
            magnus.ni
            wrote on last edited by magnus.ni
            #5

            @koahnig said in QTimer handle leak from inside Qt?:

            @magnus.ni

            Hi and welcome to devnet forum

            This is merely a user's forum. Your question is probably better suited in the developer's mailing list.

            Also your Qt version is fairly old. Can't you update to more recent versions? We have already version 5.12.

            Thank you very much. I'm afraid this won't be possible. Maybe we can switch to 5.6 in the nearest future (since we're stuck to msvc2010 and 5.6 is the latest build supporting it)

            @dheerendra said in QTimer handle leak from inside Qt?:

            If the process is running you can get the details of handles which are open. Either use process explorer or sone other tool to see the handle details. It is possible that timer error just a manifestation of some other issue.

            Thank you. This might be possible. But I myself cannot reproduce the issue or have seen it live.

            1 Reply Last reply
            0
            • JonBJ JonB

              @magnus.ni
              There seem to be two possibilities:

              • Despite what you say, your code is somehow creating many timers (e.g. via slots). Are you freeing the QTimers when you're done with them? If you are only using QTimer::singleShot, do you need those instances, could you just use the static version?

              • As e.g. @SGaist said in https://forum.qt.io/topic/54438/solved-qt-5-4-1-qtimer-using-up-all-handles-for-window-manager-objects, it may not be the QTimer itself which is being repeatedly created. The error message could just indicate that you are using up too many Windows handles in general, e.g. from widgets or whatever else in your code. (In that link it turned out the OP was creating multiple QNetworkAccessManagers --- not saying that's you, but could be anything.)

              M Offline
              M Offline
              magnus.ni
              wrote on last edited by
              #6

              Thank you!

              @JonB said in QTimer handle leak from inside Qt?:

              @magnus.ni
              There seem to be two possibilities:

              • Despite what you say, your code is somehow creating many timers (e.g. via slots). Are you freeing the QTimers when you're done with them? If you are only using QTimer::singleShot, do you need those instances, could you just use the static version?

              I'm very seldom explicitly create timers on the heap and almost any of those are single members of a class and bound to the lifetime of the owning class.
              I didn't find any ownership problems or recursive slot mechanisms here. When I need single shot I almost always use the static version.

              • As e.g. @SGaist said in https://forum.qt.io/topic/54438/solved-qt-5-4-1-qtimer-using-up-all-handles-for-window-manager-objects, it may not be the QTimer itself which is being repeatedly created. The error message could just indicate that you are using up too many Windows handles in general, e.g. from widgets or whatever else in your code. (In that link it turned out the OP was creating multiple QNetworkAccessManagers --- not saying that's you, but could be anything.)

              I've read the thread but didn't use the QNetworkAccessManager or something familiar. I've seached the large codebase for any obvious QTimer misusages but without being able to reproduce the issue. But any idea why this might have implicitly occurred are most welcome since I already watched any QTimer construction in the code for possible side effects like this.

              Thank you very much

              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