MorrisLiang
20th May 2010, 12:19
I'm checking where is the memory-leak happening in my app.And find out this:
void setupUi(QWidget *MyWidgetClass)
{
...
hLayout1 = new QHBoxLayout();
...
verticalLayout = new QVBoxLayout();
...
horizontalSpacer_2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
...
verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
...
} // setupUi
In one of the generated ui header,in the setupUi() function,there are things created in the heap.And they don't set the parent.So,when I'm done with the QWidget,this would defintely cause memory leak if I don't manually delete them.
I know nothing is perfect,but I thought the generated file would deal with the parent thing.
So each time it generate a new version of file,do I have to check if they have set the widget's parent?Is there a way avoid this?
BTW,does someone how if there's a free memory-leak detector for c++(Windows platform)?
----------------------EDIT-----------------------------
OK,I see that they are added to another layout.Then they would be deleted if the custom QWidget is deleted.So,where is the common place of the leak?Where should I pay attention to?
void setupUi(QWidget *MyWidgetClass)
{
...
hLayout1 = new QHBoxLayout();
...
verticalLayout = new QVBoxLayout();
...
horizontalSpacer_2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
...
verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
...
} // setupUi
In one of the generated ui header,in the setupUi() function,there are things created in the heap.And they don't set the parent.So,when I'm done with the QWidget,this would defintely cause memory leak if I don't manually delete them.
I know nothing is perfect,but I thought the generated file would deal with the parent thing.
So each time it generate a new version of file,do I have to check if they have set the widget's parent?Is there a way avoid this?
BTW,does someone how if there's a free memory-leak detector for c++(Windows platform)?
----------------------EDIT-----------------------------
OK,I see that they are added to another layout.Then they would be deleted if the custom QWidget is deleted.So,where is the common place of the leak?Where should I pay attention to?