Results 1 to 6 of 6

Thread: application seems to eat up memory

  1. #1
    Join Date
    Feb 2009
    Posts
    16
    Thanks
    2
    Platforms
    Unix/X11

    Default 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

    Qt Code:
    1. memset(buff, 0, 1024);
    2. numBytes = scriptfile.readLine(buff,100);
    3. buff[39] = '\n';
    4. memset(&buff[40], 0, 1024-40);
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default 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.

  3. #3
    Join Date
    Feb 2009
    Posts
    16
    Thanks
    2
    Platforms
    Unix/X11

    Default Re: application seems to eat up memory

    thanks for the reply and sorry for the lack of information.

    Qt Code:
    1. char buff[1024];
    To copy to clipboard, switch view to plain text mode 

    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!

    any tips on how to deal with the false positives in QT?

    Thanks again

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default 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).

  5. #5
    Join Date
    Feb 2009
    Posts
    16
    Thanks
    2
    Platforms
    Unix/X11

    Default 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

    Qt Code:
    1. playthread = new playThread(this, port);
    2. serverthread = new serverThread(this);
    3. irthread = new IRThread(this, port2);
    4. scriptthread = new scriptThread(this);
    To copy to clipboard, switch view to plain text mode 

    [code]
    IRThread::IRThread(QObject *parent, QextSerialPort *port2)
    : QThread(parent),
    ThreadRunning(false),
    port2(port2),
    IRscriptPlay (false)
    [code]

    or using other peoples code:

    Qt Code:
    1. tcpServer = new QTcpServer;
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: application seems to eat up memory

    The last snippet can surely cause a memory leak.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 3
    Last Post: 6th January 2010, 17:55
  2. MDI application memory issue
    By sirQit in forum Qt Programming
    Replies: 7
    Last Post: 8th July 2009, 20:32
  3. I have memory leak on every Qt3/4 application, Qt bug?
    By saugumas in forum Qt Programming
    Replies: 3
    Last Post: 14th November 2007, 20:33
  4. Memory Leak in my Application :-(
    By Svaths in forum Qt Programming
    Replies: 4
    Last Post: 27th July 2007, 20:42
  5. How to measure memory of Qt Application,
    By rajeshs in forum Qt Programming
    Replies: 2
    Last Post: 10th July 2007, 18:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.