2010-07-07 18:50:11 Qt Memory Leak (or Fragmentation?)
Daniel Tripp (UNITED STATES)
Message: 91012
I'm running into a memory issue with Qt on uCLinux. If the text of a QLabel changes, it slowly eats memory. Is anyone else using Qt? If so, what are you doing to prevent this? I don't see any apparent leaks with the my test code, but here it is in case.
Source
main.cpp:
#include "labeltest.h"
#include <QApplication>
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
LabelTest test;
test.show();
return a.exec();
}
labeltest.cpp:
#include "labeltest.h"
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
LabelTest::LabelTest(QWidget *parent) : QWidget(parent)
{
shortWord = false;
layout = new QVBoxLayout(this);
randomLabel = new QLabel(this);
updateLabel();
layout->addWidget(randomLabel);
button = new QPushButton(this);
button->setText("Click Me");
button->setFocus();
layout->addWidget(button);
connect(button, SIGNAL(clicked()), this, SLOT(updateLabel()));
}
void LabelTest::updateLabel()
{
if(shortWord)
randomLabel->setText("Short string");
else
randomLabel->setText("This is a considerably longer string");
shortWord = !shortWord;
}
labeltest.h:
#ifndef LABELTEST
#define LABELTEST
#include <QWidget>
#include <QList>
class QLabel;
class QPushButton;
class QVBoxLayout;
class LabelTest : public QWidget
{
Q_OBJECT
public:
LabelTest(QWidget *parent = 0);
private:
QLabel *randomLabel;
QPushButton *button;
QVBoxLayout *layout;
bool shortWord;
private slots:
void updateLabel();
};
#endif
labeltest.pro:
SOURCES += main.cpp \
labeltest.cpp
HEADERS += labeltest.h
QuoteReplyEditDelete
2010-07-08 04:52:08 Re: Qt Memory Leak (or Fragmentation?)
Nikolay Chokoev (IRELAND)
Message: 91032
Probably not setting the text is the problem, but events.
Try to remove the body of "void LabelTest::updateLabel()", just leave it empty and see if you have the same problem.
The better place for this question would be:
lists.trolltech.com/mailman/listinfo/qt-interest
or Qt related forums.
QuoteReplyEditDelete
2010-07-08 11:08:43 Re: Qt Memory Leak (or Fragmentation?)
Daniel Tripp (UNITED STATES)
Message: 91053 I've removed the body of LabelTest::updateLabel(), and the issue remains. I don't see how this would be events, though. I don't have any event filters, and I'm not overriding any event functions. I've sent an e-mail to Qt-interest, but the response I've received is to use software to detect memory leaks. But, on my current dev platform, I don't have enough room to use mudflap.
QuoteReplyEditDelete
2010-07-08 11:36:11 Re: Qt Memory Leak (or Fragmentation?)
Nikolay Chokoev (IRELAND)
Message: 91057
As the Qt code is portable, you can use PC (Linux or Windows) to see what's happened. If the issue is not Qt/E related you should be able to catch it.
QuoteReplyEditDelete
2010-07-08 11:41:13 Re: Qt Memory Leak (or Fragmentation?)
Daniel Tripp (UNITED STATES)
Message: 91058
That's the thing, I can't replicate this with Qt/E 4.5.1 built for my workstation.
QuoteReplyEditDelete
2010-07-08 11:47:24 Re: Qt Memory Leak (or Fragmentation?)
Nikolay Chokoev (IRELAND)
Message: 91059
On a workstation you should use Qt Linux/X11, not Qt/E.
However, if you run this example and monitor the memory usage, you should notice an increase...
QuoteReplyEditDelete
2010-07-08 12:06:36 Re: Qt Memory Leak (or Fragmentation?)
Daniel Tripp (UNITED STATES)
Message: 91061
I'm running Qt/E 4.5.1 with QVFB on my dev machine. Is there a reason I need to use Qt Linux/X11 instead? I'm still not seeing the memory increase after repeated clicks. Am I missing something obvious? I'm checking /proc/PID/status for memory stats.
QuoteReplyEditDelete
2010-07-08 14:23:37 Re: Qt Memory Leak (or Fragmentation?)
Nikolay Chokoev (IRELAND)
Message: 91072
I meant to run it on pure Qt (Linux or Windows). QVFB makes the Qt to behave in different way (diferent modules are included, other are excluded) and you may not see what you see otherwise.
Try it in 'normal' Qt/Linux/X11 or Qt/Windows if you have access to.
QuoteReplyEditDelete
2010-07-08 17:11:01 Re: Qt Memory Leak (or Fragmentation?)
Daniel Tripp (UNITED STATES)
Message: 91083 I've compiled Qt/X11 4.5.1 for my workstation, compiled the LabelTest app, and the memory issue does not show up. Can anyone test this on Blackfin hardware with uCLinux to verify the memory issue? Where's the best place to verify this?
QuoteReplyEditDelete
2010-07-08 17:41:56 Re: Qt Memory Leak (or Fragmentation?)
Nikolay Chokoev (IRELAND)
Message: 91084
Try to reconfigure and rebuild the Qt for Blackfin with qvfb enabled. Then rebuild and run your Qt app as usual. This helped me to workaround some problems with Qt, may help in this case as well.
QuoteReplyEditDelete
2010-07-09 10:29:13 Re: Qt Memory Leak (or Fragmentation?)
Daniel Tripp (UNITED STATES)
Message: 91106 I've enabled QVFB in buildroot, it's not making a difference. FYI, I'm still running the example with an empty LabelTest::updateLabel(), simply clicking the button is running up the memory usage.
QuoteReplyEditDelete
2010-07-11 03:15:12 Re: Qt Memory Leak (or Fragmentation?)
Nikolay Chokoev (IRELAND)
Message: 91133
You can make your button, subclassing QLabel, catching the mouse events and drawing on the paint event...