I use so-called QThreadPool and I throw in it the pointer on QRunnable . Such code:

 void QThreadPoolServer::incomingConnection(qintptr handle) { QSocketRunnable *runnable = new QSocketRunnable(handle); this->thread_pool->start(runnable); } 

Do I need to clean QRunnable ? Or the QThreadPool::start() method will do everything itself?

    1 answer 1

    In the help :

    If auto-deletion is enabled, QThreadPool will automatically delete this runnable after calling run(); otherwise, ownership remains with the application programmer.

    What is translated:

    If auto-deletion is enabled (by default, this is the case), then the thread pool will automatically destroy the QRunnable object after the execution context exits from the QRunnable::run() method. In the opposite case, the responsibility for deleting the object lies with the caller (the application developer).


    A warning

    Care should be taken when using the automatic deletion of QRunnable objects and QThreadPool::releaseThread() / QThreadPool::reserveThread() . In some cases, memory leaks are possible.