This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
ab396356
In need of some credit
Posts: 5 Joined: Fri Jun 01, 2018 6:46 am
Post
by ab396356 » Fri Jun 01, 2018 9:38 am
I apologize in advance if this was discussed before; I did a quick search before, and didn't find anything pertaining to this topic.
There are memory leaks in the
latest 3.1.1 Hello World example code:
Code: Select all
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame();
frame->Show(true);
return true;
}
In the code snippet,
frame is not deleted, and
~MyFrame() is not called. I am aware that I'm being pedantic over example code but I'd like to know if there is a good reason to write it this way?
PB
Part Of The Furniture
Posts: 4204 Joined: Sun Jan 03, 2010 5:45 pm
Post
by PB » Fri Jun 01, 2018 11:23 am
I believe that you are not pedantic, you are just wrong. ;) See e.g.
http://docs.wxwidgets.org/trunk/overvie ... etion.html
Or, did you actually try to debug the code, place the breakpoint the frame's dtor and observed it was never called?
Edit: Here's a picture as a proof, where the breakpoint in the frame's dtor is hit upon closing the frame. :)
framedtor.png
You do not have the required permissions to view the files attached to this post.
ab396356
In need of some credit
Posts: 5 Joined: Fri Jun 01, 2018 6:46 am
Post
by ab396356 » Fri Jun 01, 2018 11:35 am
Thanks for clearing up my confusion.
PB wrote: Or, did you actually try to debug the code, place the breakpoint the frame's dtor and observed it was never called?
No I haven't, yet. I'm only beginning with wxWidgets and I didn't expect it to do tricks like this.
PB
Part Of The Furniture
Posts: 4204 Joined: Sun Jan 03, 2010 5:45 pm
Post
by PB » Fri Jun 01, 2018 12:57 pm
ab396356 wrote: I'm only beginning with wxWidgets and I didn't expect it to do tricks like this.
I believe that all major C++ GUI toolkits (Qt, MFC, wxWidgets) do it (i.e., manage window pointers) this way...
eranon
Can't get richer than this
Posts: 867 Joined: Sun May 13, 2012 11:42 pm
Location: France
Post
by eranon » Fri Jun 01, 2018 1:27 pm
Hello, It should be of some help to understand the overall picture:
https://wiki.wxwidgets.org/Avoiding_Memory_Leaks
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]