Results 1 to 11 of 11

Thread: Memory leak?

  1. #1
    Join Date
    Aug 2007
    Posts
    27
    Qt products
    Qt4
    Platforms
    Unix/X11

    Exclamation Memory leak?

    Hi there.

    In my program I`m using a Main Window which is a subclass of QWidget and from it, by pressing some buttons, I create new windows which are also subclasses of QWidget with parent set to 0 and which have the widget attribute Qt::WA_DeleteOnClose set.

    The problem that I`m having is when monitoring the memory my application uses. Every time I open a new window inside the application, the memory usage rises but when I close it, it doesn't drop back. This repeats its self for every window I open and the memory stacks up to even 100mb VmSize at 7+1(the main window) windows opened. (VmRss also stacks up).

    I`ve connected the destroyed signal for the windows and tried to see if it it gets called and it does; but what is there to be done if the memory keeps rising?

    Any help?

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Memory leak?

    Do you make any allocations by yourself additional to opening the windows?

  3. #3
    Join Date
    Aug 2007
    Posts
    27
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Memory leak?

    I use code like this when creating a new window:
    Qt Code:
    1. Window *window = new Window( arg1, arg2 );
    2. window->show();
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Memory leak?

    Yes, but does the window class itself make some allocations inside?

    Regards

  5. #5
    Join Date
    Aug 2007
    Posts
    27
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Memory leak?

    Of course it does.

    All the gui is created in this class ( labels, groupboxes, qtrees, etc ) and some QLists and QMaps.

    The widgets should get destroyed by qt when destroying the window containing them. The lists I don`t know, but I tried doing a 'delete list' for example in closeEvent and I got some degub messages and a crash saying 'double free or corruption (!prev): 0x0965a8' so I imagine they are deleted in the destructor.

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Memory leak?

    The widgets won't get deleted if they are parentless.
    The list also, if they are allocated dynamically and they don't have parents, they won't get deleted automatically.

    So, maybe you should take a look at those debug messages. If the lists contain complex data structures, then those structures should have destructors to clean up after themselves.

    Regards

  7. #7
    Join Date
    Aug 2007
    Posts
    27
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Memory leak?

    All the widgets have proper parents. Except for some QTreeWidgetItems that are added to the tree with addTopLevelitem and when the tree gets destroyed, they should too.

    The lists are actually (not very efficient but nice to code at) QList<QMap<QString, QString> > * which I delete inside closeEvent. ( no more crash, the earlier rash was about me deleting a qprocess my bad )

    From what I know, QStrings are managed by Qt.

    So the question remains. Why doesn't the memory free up when each window closes?

  8. #8
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Memory leak?

    Assuming that you are on linux, read this:http://www.qtcentre.org/forum/f-qt-p...mory-8569.html.

    Although, if there aren't any leaks, the physical mem usage should drop.
    vmrss is the total amount of memory used by your application, both physical and virtual.

    Regards

  9. #9
    Join Date
    Aug 2007
    Posts
    27
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Memory leak?

    Yes, I use Fedora 7.

    When I open the main window, the VmRss stays at ~16Mb. After opening 2 windows inside the my application, VmRss rises at ~36Mb. After I close the two windows it stays the same.
    VmSize does the same, only the value is higher as expected.

    I mention that the main window is an instance of the class MainWindow and the windows that open by pressing buttons are instances of the class Window. So they should get dealocated. :|

    I tried the valdring tool and I do have some relatively minor leaks, most of them tracing back to qt, xerces-c and expat inside xerces which I use.

    I get alot of uninitialized variables warnings and some overflows from what I understand, all of them tracing back to qt or xerces or some X11 lib. On my sources, most of them point merely to code like QApplication qapp( argc, argv ); or simple stuff like that so I can't be screwing things there.

    I`ve read about the linux memory manager in the suggested thread, but here the used memory keeps rising.The more windows I open, the more memory it eats.

    Nothing pointed out by valdrind ends up in significant parts of my code, only in the libraries that the program uses :|

    I don`t understand.

  10. #10
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Memory leak?

    Then it is possible to have some leaks.
    But for someone to help you, it is required that you post some code.
    This is only if you can. Even an example that reproduces the problem would suffice.

    Regards

  11. #11
    Join Date
    Aug 2007
    Posts
    27
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Memory leak?

    Yeah, I`m fully aware of that, but like in the thread u`ve suggested, the code is very large and reducing it to a significant example would be really hard, taking in consideration also that I don't know exactly which part of it is responsable for this behaviour.

    What about the claims that the libraries to which I`m linking (qt, xerces-c, x11) are leaking moderatly or using unitialized data? Am I misinterpreting valgrind's output, is it erroreous, or it is just something that does happen commonly?

    Thanks for the reply troughout this thread but I think I`ll leave this behind as the conditions in which this problem could get very disturbing require a relatively disturbed user.

Similar Threads

  1. Memory leak detection
    By Sid in forum Qt Programming
    Replies: 8
    Last Post: 4th May 2011, 22:38
  2. QPixMap and Memory leak
    By Krish_ng in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2007, 14:18
  3. Memory Leak in my Application :-(
    By Svaths in forum Qt Programming
    Replies: 4
    Last Post: 27th July 2007, 19:42
  4. Any reason for memory leak?
    By steg90 in forum Newbie
    Replies: 2
    Last Post: 10th May 2007, 15:00
  5. Qt 4.1 Memory Leak
    By blackliteon in forum Qt Programming
    Replies: 14
    Last Post: 10th February 2006, 12:47

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.