minor memory leaks warning in MSVC

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
MagickPanda
Experienced Solver
Experienced Solver
Posts: 81
Joined: Wed Oct 19, 2016 1:41 pm

minor memory leaks warning in MSVC

Post by MagickPanda »

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.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: minor memory leaks warning in MSVC

Post by PB »

MagickPanda wrote:button/label that allocated with 'new' then added to frame via 'addChild' meothd.
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
Experienced Solver
Experienced Solver
Posts: 81
Joined: Wed Oct 19, 2016 1:41 pm

Re: minor memory leaks warning in MSVC

Post by MagickPanda »

Thanks I will see if I can avoid using instance of adding child manually.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: minor memory leaks warning in MSVC

Post by PB »

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.
Post Reply