Hi all
I'm stuck with this problem for a couple of weeks now, and my normal human brain can't tell me what's going wrong.
I've created my own class, inheriting from QThread. Nothing weird in calling it:
MyThread *thread = new MyThread();
thread->start();
while(thread->isRunning) ;
delete thread
;
I know I don't need a pointer in the code above, but the problem remains even without it.
The only code implemented in the thread class is run()
void MyThread::run()
{
cols = 8000;
rows = 9000;
double progress = 0.0;
double add = 100.0/(cols*rows);
for(int col = 0; col < cols; col++)
{
for(int row = 0; row < rows; row++)
{
progress += add;
}
}
}
So basically what the code does, it increases the progress (between 0 and 100). The last += add; will make progress 100;
There are absolutely no pointers in the thread.
Now the weird thing: After the execution of the thread, my program shows a memory usage between 10 and 40mb (after the thread finished, my program is basically in idle).
When I remove progress += add; from the code, the memory usage is only a few bytes (as it should be, since all the code inside run() is now out of scope). When I replace progress += add; with something like: progress = 1; then I also don't have a memory loss.
So the problem is somewhere in adding to a double value (memory loss with int instead of double is between 5mb-20mb).
Does anyone have a clue why this is happening, since I don't have any clue why variables that are out of scope can still take up memory?