I recently noticed my app project in MSVC is giving alot memory leak warnings upon exit.
So I added memory allocation macro to pin point the function/line of code in those warnings, I found that some leaks are related to wxWidgets frame's 'child' elements, e.g:a button/label that allocated with 'new' then added to frame via 'addChild' meothd.
I wonder if this is a false alert/intended behavior, since the memory leaks amount is pretty low(a few bypes per leak warning) and wont accumulate enough amount to crash I assume.
minor memory leaks warning in MSVC
-
- Experienced Solver
- Posts: 81
- Joined: Wed Oct 19, 2016 1:41 pm
Re: minor memory leaks warning in MSVC
You should not get any memory leaks like this unless you do something wrong, the parent will delete all its children when necessary. I assume you do not actually call wxWindow::AddChild() by yourself as that would be quite likely a bad idea to do.MagickPanda wrote:button/label that allocated with 'new' then added to frame via 'addChild' meothd.
-
- Experienced Solver
- Posts: 81
- Joined: Wed Oct 19, 2016 1:41 pm
Re: minor memory leaks warning in MSVC
Thanks I will see if I can avoid using instance of adding child manually.
Re: minor memory leaks warning in MSVC
As the documentation states, AddChild() is not be called from the user code. Just call the child window constructor (or its Create() method) with a proper parent. That is how is it done, see e.g. wxWidgets samples.