Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Emit signals too frequently can eat up the memory?



  • I run a test program, creating a new thread and emit a signal in while(1) loop as quick as possible. And I find that the memory is used up very quickly.

    So in real programming, should I check something before I emit a signal?


  • Lifetime Qt Champion

    @Mr-Pang said in Emit signals too frequently can eat up the memory?:

    emit a signal in while(1) loop as quick as possible

    This is not going to work as a loop is blocking the event loop. All signals will be processed when the loop is finished.


  • Moderators

    @jsulm I hadt to be reminded myself, but that is not true.

    You can not reacte to signals in that thread, that has the while loop running. But you can send (emit) signals to other threads and process them in slots there without problems.

    @Mr-Pang
    and, that can be a problem. Even more so, when your signal has arguments, as the data from that argument has to be copied for each signal that is emitted. If no argument you still have some memory allocated for each signal

    Signals are not simply forgotten, they are queued up to be processed in the next eventloop cycle. That means the while-loop may create thousands of signals for the other thread, while the other threas had no chance to process any. During processing the signals new signals are emitted and queueud as well. So this can and will run out of controll quickly.


Log in to reply