wxWidgets docs: Hello World example (pedantry) Topic is solved

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.
Post Reply
ab396356
In need of some credit
In need of some credit
Posts: 5
Joined: Fri Jun 01, 2018 6:46 am

wxWidgets docs: Hello World example (pedantry)

Post by ab396356 »

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

Re: wxWidgets docs: Hello World example (pedantry)

Post by PB »

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
framedtor.png (36.59 KiB) Viewed 5101 times
ab396356
In need of some credit
In need of some credit
Posts: 5
Joined: Fri Jun 01, 2018 6:46 am

Re: wxWidgets docs: Hello World example (pedantry)

Post by ab396356 »

PB wrote:I believe that you are not pedantic, you are just wrong. ;) See e.g. http://docs.wxwidgets.org/trunk/overvie ... etion.html
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
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxWidgets docs: Hello World example (pedantry)

Post by PB »

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...
User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: wxWidgets docs: Hello World example (pedantry)

Post by eranon »

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"]
Post Reply