Page 1 of 1

wxWidgets docs: Hello World example (pedantry)

Posted: Fri Jun 01, 2018 9:38 am
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?

Re: wxWidgets docs: Hello World example (pedantry)

Posted: Fri Jun 01, 2018 11:23 am
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 5495 times

Re: wxWidgets docs: Hello World example (pedantry)

Posted: Fri Jun 01, 2018 11:35 am
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.

Re: wxWidgets docs: Hello World example (pedantry)

Posted: Fri Jun 01, 2018 12:57 pm
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...

Re: wxWidgets docs: Hello World example (pedantry)

Posted: Fri Jun 01, 2018 1:27 pm
by eranon
Hello, It should be of some help to understand the overall picture: https://wiki.wxwidgets.org/Avoiding_Memory_Leaks