Project

General

Profile

WBoxLayout::addStretch (Definite Memory loss is reported by valgrind)

Added by Ehsan Mahdavi over 8 years ago

Hi again,

I am using libwt(3.3.4+dfsg-1~trusty~pgquiles1) on Ubuntu X64 14.04.4.

Analyzing memory leaks with valgrind am getting a bunch definite memory loss reports when using WBoxLayout::addStretch(...).

The problem is getting worse because am using it in a template class.

Is that a bug in Wt or what? Should I feel a bug report?

Thanks


Replies (4)

RE: WBoxLayout::addStretch (Definite Memory loss is reported by valgrind) - Added by yyyy yyyy over 8 years ago

Could you show us the codes?

It would be nice if you can show us minimum codes which could reproduce this issue.

Thanks

RE: WBoxLayout::addStretch (Definite Memory loss is reported by valgrind) - Added by Ehsan Mahdavi over 8 years ago

Yes , of course...

I attached the code and valgrind sample output

Please mention that I have tried to delete every single object in destructor (commented out in the attached code) and it is not successful.

Actually when I try to delete all the layouts manually it will generate exception (and valgrind complains about invalid free())

thanks

RE: WBoxLayout::addStretch (Definite Memory loss is reported by valgrind) - Added by yyyy yyyy over 8 years ago

The possible problem

Well, there are two problems I saw

1 : You should not delete the layout_grid_main by yourself,

let parent of it do this task

2 : I do not see you initialize "WUI_Table_View_Form" with parent

In the world of c, we have two ways to make memory management become

easy to mange, the first one is RAII,second is the one Qt provided---parent and child

Wt mimic the parent and child memory management system of Qt

That is, as long as the object you new has a parent

this object will be deleted when the parent of it die

example :

//now app become parent of my_widget

my_widget(WApplication *app) : WContainerWidget(app)

{

auto *hlayout = new WHBoxLayout;

//ok_button become child of hlayout

hlayout->addWidget(ok_button = new WPushButton);

//this become parent of hlayout

setLayout(hlayout);

}

If you wonder the widget has parent or not, you could called member function parent()

to show the address of the parent, or inherit the class and call the member function

"hasParent()", as long as the object has a parent, when the parent die, the object will be

released. If the object already has a parent and you free it manually, you may delete the object

at the same address two times, this cause undefined behavior.

You could look at this post[[[http://redmine.emweb.be/boards/2/topics/12324]]] if you want to know more about parent and child.

ps : It would be better if you reorganized your codes,

make it able to compile,run with minimum lines of codes

yet able to reproduce the problem

RE: WBoxLayout::addStretch (Definite Memory loss is reported by valgrind) - Added by Ehsan Mahdavi over 8 years ago

Hi,

Thanks for ur information about my beautiful world of c,

I knew about the parent and child relationship and the memory management scheme, as I have 5 or 6 years of qt programming experience.

However, back in 2014 when I started using wt I noticed that the objects sometimes won't get deleted, like when the client refreshes the page. So I started to do the RAII memory management as I considered it as a wt bug.

This was a false experience because some times later I understood that the wt will delete them after a period of time which is identified in wt_config.xml file by x fields.

This wrong habit got persistent.

You were right, I must let the parent child memory management do the job, and it fixed the issue.

Thanks

    (1-4/4)