Re: Memory leak weirdness
Did you compile the app in debug mode?
Quote:
make clean
qmake -config debug
make
PS. You'll need debug version of Qt as well (notice that's there's a link for building debug libs in Start-menu).
Re: Memory leak weirdness
I compiled in debug mode yes. As far as Qt goes, I compiled it from the source yesterday and I just checked and it seems debugging is on by default when running configure & make, so I'm guessing that isn't the problem either.
Concerning enabling debugging stuff, my .pro file contains:
Quote:
QT += debug
QMAKE_CXXFLAGS_DEBUG += -pg
QMAKE_LFLAGS_DEBUG += -pg
Re: Memory leak weirdness
Hm, k, I found the line that caused the illegal pointer error. But now I'm looking at 32 memory leaks and I have no idea where to look, because I'm getting addresses instead of files. Has anyone tried using this memory leak tool in Windows? Did it work as advertised on the website? If so, how did you implement it?
* Edit: Ok, managed to fix it. Some mistunderstanding on my part. I knew I had to load the debug_new.h before system headers, but I didn't think Qt headers counted as system headers.
Re: Memory leak weirdness
Ah well, while we're at it. I get odd results like this:
Quote:
Leaked object at 003DE248 (size 20, GUI\MainWindow.cpp:83)
Leaked object at 0400C538 (size 20, GUI\MainWindow.cpp:88)
Leaked object at 003DFE78 (size 16, GUI\MainWindow.cpp:93)
Leaked object at 003DF750 (size 20, GUI\MainWindow.cpp:98)
Leaked object at 040218C8 (size 20, GUI\MainWindow.cpp:107)
Those lines are:
Quote:
centralwidget = new QWidget(this);
gridLayoutContainer = new QWidget(centralwidget);
gridLayout = new QGridLayout(gridLayoutContainer);
lblStatusBar = new QLabel(centralwidget);
lblEmpty = new QLabel(centralwidget);
All of those variable are declared in my header file as private pointers.
In my destructor ~MainWindow, I have:
Quote:
delete lblStatusBar;
delete lblEmpty;
delete gridLayout;
delete gridLayoutContainer;
delete centralwidget;
As far as I can see, on destruction of the object, I delete every one of the objects that are the leaks according to the tool. The ~MainWindow gets called automatically when I do "delete mainWindowInstance;" right? Do I really have memory leaks or is the memory leak tool for some reason unable to handle this?
Re: Memory leak weirdness
In fact, you wouldn't even need those deletes since every QObject automatically deletes its children upon destruction. Does the main window itself get properly destructed? Yeah, could be that the tool is not able to handle Qt that well after all.. :p
Re: Memory leak weirdness
Oh, well, then it's definitely the tool. Ok, time to delete some "delete" stuff :).
Re: Memory leak weirdness
Just to assure, in main() you do either
- allocate the main window object on the stack
- allocate the main window object on the heap and delete it by hand
- allocate the main window object on the heap and set attribute Qt::WA_DeleteOnClose
right?
Re: Memory leak weirdness
The main window object is on the heap, the QApplication on the stack, but there shouldn't be a leak there or the tool would say so (well, maybe not, it's obviously not perfect). Here's the stripped down code from my main:
Code:
int main(int argc, char *argv[])
{
MainWindow *diag = new MainWindow();
diag->show();
int iReturn = app.exec();
delete diag;
return iReturn;
}
Re: Memory leak weirdness
Alright good, so it falls to the second option. Btw, you could just allocate it on the stack as well, couldn't you? ;)
Re: Memory leak weirdness
Yeah, true. I think I stole the basic code from some tutorial and just went with it. I've only been programming in C++ for 1 week. I thought it would be harder. Ok, I have some memory management to do, for other than that, it all comes down to the same stuff as Java, PHP, ... Thx for the help & assuring me the tool it at fault :).