application seems to eat up memory
hello
I am a little bit of a noob here, so please forgive me if i am posting this all wrong.
i have quite a hefty QT application that seems to eat up memory, then get slower and slower.
Posting code will be difficult as its quite large.
i have run valgrind and the only errors i can see are related to qt libraries.
Does anyone have some ideas as to where i can look at problem items?
i am opening and parsing a few files, but i am pretty sure i close them when finished before opening others.
essentially i am parsing a script file, which in turn open up other script files to process some data.
i am reading some lines of code using memset.
does this automatically delete itself? (its in a loop as such so i think that it gets re-written each time around.
for instance
Code:
memset(buff, 0, 1024);
numBytes = scriptfile.readLine(buff,100);
buff[39] = '\n';
memset(&buff[40], 0, 1024-40);
will this re-write the buffer each time??
any clues as to how i can debug this will be grateful.
i know its a bit vague, but the application is quite large and i have no idea where the problem section could be.
thanks in advance
P
Re: application seems to eat up memory
What is buff? It is a pointer to ...? How do you manage it.
That being the only code you posted, it's very hard to know where the problems are.
Most of the time, it's pointer usage.
Valgrind can help you, but you need to deal with the false positives in Qt.
Re: application seems to eat up memory
thanks for the reply and sorry for the lack of information.
what i have noticed is that i am defining the code above outside of the function itself, so its kind of global for that thread.
would it be better if i kept it in the same function as i initially posted??
the only reason i am asking about memset is that i have no idea what else i could do! :o
any tips on how to deal with the false positives in QT?
Thanks again
Re: application seems to eat up memory
This buffer is allocated on the stack and is not the cause of your memory leak: it does not grow and will be cleaned up when it leaves scope. Your memset code is largely unnecessary because QIODevice::readLine() always ensures a terminating NUL character.
You need to look at everywhere your program uses the new operator to make sure that the allocated memory is always deleted. Any plain-old-data structure you allocate on the heap is definitely your problem to ensure deletion. If you create QObjects without a parent then you are responsible for deletion (or allocation to a parent QObject).
Re: application seems to eat up memory
Thanks for the response.
I've had a quick look and as far as i can tell here there are only a few new operators - mainly used to set up threads:
e.g
Code:
playthread = new playThread(this, port);
serverthread = new serverThread(this);
irthread = new IRThread(this, port2);
scriptthread = new scriptThread(this);
[code]
IRThread::IRThread(QObject *parent, QextSerialPort *port2)
: QThread(parent),
ThreadRunning(false),
port2(port2),
IRscriptPlay (false)
[code]
or using other peoples code:
Re: application seems to eat up memory
The last snippet can surely cause a memory leak.