Results 1 to 3 of 3

Thread: qt memory management debugging with massif

  1. #1
    Join Date
    Mar 2011
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question qt memory management debugging with massif

    Hi,

    I have a question regarding memory debugging with qt.

    First a short description of what my program does:
    From a separate thread (which is started by a user action), I query a sqlite-database, transform the resulting (up to a few million) rows into objects which I create the following way:
    Qt Code:
    1. QSharedPointer<MyObject> m = QSharedPointer<MyObject>(new MyObject));
    To copy to clipboard, switch view to plain text mode 
    All these objects are appended to a QList which is then emitted via a signal.
    After the thread which created the objects and the slot which connects to this signal terminated, the objects should be all deleted, as no one is referencing them anymore and they are packed into a QSharedPointer.

    Now to my problem:
    when I let the program run with the help of massif (valgrind), I can clearly see that all the memory is freed again. But when I look at the total memory consumption of the process (now without massif), It doesn't free the memory, but stays at the same level until I quit the application.
    So I ran the application again with massif, but now with the commandline option --pages-as-heap=yes, which intersects the calls more low-level memory-allocation calls. And with this, I can really see that the memory does not get freed anymore.
    See the images for a comparison between massif with and without the command line argument --pages-as-heap=yes

    So my Question is:
    why is the memory not really freed anymore?

    Does Qt have its own memory-cache which it reuses for new allocations? If yes, can I somehow change this behaviour?

    I'm using qt 4.7.3 under linux.
    Attached Images Attached Images

  2. #2
    Join Date
    Mar 2011
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qt memory management debugging with massif

    one little additional remark:
    today, I tested my application under windows 7 and there, all the memory get's freed again. So there shouldn't be a memory leak in my application at least.

  3. #3
    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: qt memory management debugging with massif

    The operating system holds the memory assigned to the process for future use. If some other process allocates a big chunk of memory, the memory will be freed and reassigned to it. That's totally normal behaviour.

    If you use QSharedPointer then you can see if the memory is released by setting a deleter callback while creating the shared pointer and writing some debug statement in the deleter to see how many times it gets called.

    As a side note, I don't see the point of using QSharedPointer in your situation. You should allocate your objects on the stack and not on the heap if that's just the result of an sql query. Then you wouldn't have such problems.
    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. Memory management in Qt?
    By wookoon in forum Qt Programming
    Replies: 7
    Last Post: 6th November 2010, 19:20
  2. Memory Management Reg
    By BalaQT in forum Newbie
    Replies: 10
    Last Post: 4th February 2010, 13:43
  3. Memory management
    By cyberboy in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2008, 21:48
  4. Memory management questions (im new to Qt)
    By scarvenger in forum Qt Programming
    Replies: 2
    Last Post: 6th May 2007, 08:41
  5. Memory management in QT
    By Gayathri in forum Qt Programming
    Replies: 1
    Last Post: 17th November 2006, 08:21

Tags for this Thread

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.