Why qThreadpool do not clear its queue
-
wrote on 14 Nov 2017, 06:41 last edited by Ehsun
I have wrote the following code by using qthreadpool. The problem is that qt does not free the memory after finishing the application. My codes are attached bellow (noting change even I uncomment the commented parts). Could you please help me?
Main
Header file
Implementation -
I have wrote the following code by using qthreadpool. The problem is that qt does not free the memory after finishing the application. My codes are attached bellow (noting change even I uncomment the commented parts). Could you please help me?
Main
Header file
Implementation@Ehsun Why do you allocate myThread on the heap? Allocate it on the stack. You also should delete all myRunnable instances you created when they are not needed anymore.
P.S.: it is easier to post the source code directly here instead of photograph your display and post links to the pictures. -
wrote on 14 Nov 2017, 08:44 last edited by
-
Hi,
To add to my fellow, QThreadPool deletes the runners by default however, with your disabled destructor, all the int arrays you allocated won't get cleaned. Either use a two dimensional vector or properly clean your
myList
content. -
@Ehsun what destructor exactly?
You allocate memory inMain
as well as inImplementation
without freeing it later/on program exit.only
Header file
is free of leakage. -
wrote on 14 Nov 2017, 10:41 last edited by
@J-Hilk you can uncomment the comented part in the destructor of myRunnable class or uncomment the for loop in run() method but after that nothing will change and no memory will free at the end
-
Just one thing, when an application quits, the memory it used is freed. What the OS does with this newly freed memory is by no mean related to Qt and varies from one platform to another.
So what exactly are you observing and how ?
-
Just one thing, when an application quits, the memory it used is freed. What the OS does with this newly freed memory is by no mean related to Qt and varies from one platform to another.
So what exactly are you observing and how ?
wrote on 14 Nov 2017, 10:53 last edited by JonB@SGaist
Well under Windoze & Linux all memory is certainly freed on executable exit, so for Qt I can only imagine MacOS could work differently. So as you say the OP needs to explain what behaviour he is observing, and that the Qt app really has terminated. -
Like I already wrote, it has nothing to do with Qt. Qt is a C++ framework, it doesn't do anything special with respect to memory management.
So yes, since the OP wrote that the memory was not freed after the application ended then he needs to elaborate on that.
10/10