PDA

View Full Version : Memory Leak in my Application :-(



Svaths
6th March 2007, 13:50
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

wysota
6th March 2007, 14:13
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.

bruccutler
25th July 2007, 03:36
Can you further define "QObject Children" of an object.

marcel
25th July 2007, 04:47
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 withinAlso 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

bruccutler
27th July 2007, 19:42
I particularly like the QObjectCleanupHandler. This will be very helpful in tracking memory problems too.