Results 1 to 5 of 5

Thread: Memory Leak in my Application :-(

  1. #1
    Join Date
    Jul 2006
    Posts
    16
    Thanks
    4
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Question Memory Leak in my Application :-(

    Hi,

    I am using Qt 3.3 Embedded version obviously on an Embedded platform..

    Scenario:
    I have 'n' different widgets which I open and close depending on the user inputs.

    Every time, I feel that widget is no longer required, I use close(true) to close the widget.

    Since I created my widgets with "WDestructiveClose" flag, I was pretty confident that the widget would be deleted rather tha being hidden.

    I had "qWarning"s in my widget's destructor and since they were getting printed, I took it granted that all the child widgets / components are deleted and the corresponding memory is being freed.

    Problem:

    There is a memory leak happening when a widget is being opened and closed. The memory usage is building up and causing a disastrous effect.... and mine is an Embedded system....scarce of memory...

    Doesn't Qt free up all the memory, it has allocated once the widget's destructor is called??
    Is there any tool / way to find out where exactly the memory leak is happening....?

    Any suggestion is surely a Welcome....

    Thanks in Advance...

    Regards,
    Svaths

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: Memory Leak in my Application :-(

    Try using Valgrind to find the leak. Qt deletes all QObject children of a QObject that gets deleted. You have to free all other memory yourself.

  3. #3
    Join Date
    Jan 2007
    Posts
    91
    Thanks
    21
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Memory Leak in my Application :-(

    Can you further define "QObject Children" of an object.

  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 in my Application :-(

    That means all the QObject's returned by a call to QObject::children().
    A QObject can become the child of another QObject through any number of means( they really are quite a few, I am not going to list them all), but generally:
    • When you create widgets or objects and pass a parent to the constructor
    • When you add widgets(that don't yet have a parent) to a layout(that doesn't yet have a parent) and you set that layout to another widget. The latter becomes the parent for both the layout and the children within
    Also note that you can change the order in which the children appear in the list by QWidget::raise and QWidget::lower.

    If you're interested in these matters, then of special interest should be QObject::deleteLater and QObject::destroyed.

    Regards

  5. The following user says thank you to marcel for this useful post:

    bruccutler (27th July 2007)

  6. #5
    Join Date
    Jan 2007
    Posts
    91
    Thanks
    21
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Memory Leak in my Application :-(

    I particularly like the QObjectCleanupHandler. This will be very helpful in tracking memory problems too.

Similar Threads

  1. 'memory leak' threads on QT centre
    By locus in forum Qt Programming
    Replies: 1
    Last Post: 29th January 2007, 17:44
  2. Replies: 3
    Last Post: 8th December 2006, 18:51
  3. Memory leak
    By vvbkumar in forum General Programming
    Replies: 4
    Last Post: 2nd September 2006, 15:31
  4. Memory leak
    By zlatko in forum Qt Programming
    Replies: 8
    Last Post: 28th March 2006, 19:02
  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.