wxWidgets docs: Hello World example (pedantry)  [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.
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)

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

Re: wxWidgets docs: Hello World example (pedantry)  [SOLVED]

Postby 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/overview_windowdeletion.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 1225 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)

Postby ab396356 » Fri Jun 01, 2018 11:35 am

PB wrote:I believe that you are not pedantic, you are just wrong. ;) See e.g. http://docs.wxwidgets.org/trunk/overview_windowdeletion.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: 1686
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxWidgets docs: Hello World example (pedantry)

Postby 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...

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)

Postby 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"]


Return to “General Development”

Who is online

Users browsing this forum: ONEEYEMAN and 1 guest