Author Topic: wxSmith memory management?  (Read 5856 times)

Offline BentFX

  • Multiple posting newcomer
  • *
  • Posts: 18
    • BentFX
wxSmith memory management?
« on: March 04, 2012, 09:14:55 pm »
Please forgive me if I'm way off base, I am a bit of a newbie. I certainly don't fully understand C++ memory management, but I do try to follow the rule of 'delete' everything you 'new'. I notice in a new project using the wxWidgets wizard and wxSmith as the GUI builder, new is called 7 times and delete is not called at all. Valgrind(which I'm also very new to) lists most of these newed items as possibly lost.

Are they actually being lost? Should I be deleting these items?

Search project files for "new"...
Code
testwxApp.cpp|26|testwxFrame* Frame = new testwxFrame(0);|
testwxMain.cpp|65|MenuBar1 = new wxMenuBar();|
testwxMain.cpp|66|Menu1 = new wxMenu();|
testwxMain.cpp|67|MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);|
testwxMain.cpp|70|Menu2 = new wxMenu();|
testwxMain.cpp|71|MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL);|
testwxMain.cpp|75|StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));|

StatusBar1 is the only member variable which can be deleted in the frame destructor. The menu items are declare as local variables in the frame initialization, but it breaks the menus and the app if I delete them at the end of the initialization function. Does wxWidgets properly free that memory?

Should I be saving those addresses for deletion in the frame destructor, or am I just overthinking things?
--------
Xubuntu 11.10
Code::Blocks Release 10.05 rev 0 gcc 4.6.1 Linux/unicode - 64 bit
(Please don't turn this into an argument about downloading a nightly, unless you know that the nightly would address my specific concerns.)
Whenever I go to Walmart I always request an intrusive pat-down from the greeter. It looks good on his resume, and it makes us all just a little bit safer.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: wxSmith memory management?
« Reply #1 on: March 04, 2012, 09:17:38 pm »
Does wxWidgets properly free that memory?
Yes, please read a book about wxWidgets or its documentation.

Probably this one: http://docs.wxwidgets.org/stable/wx_allocatingobjects.html#allocatingobjects
On the wx's wiki you can find an article about using valgrind with wxwidgets programs.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline BentFX

  • Multiple posting newcomer
  • *
  • Posts: 18
    • BentFX
Re: wxSmith memory management?
« Reply #2 on: March 04, 2012, 09:25:57 pm »
Thank you!

I will read that and I hope I understand some of it. It's often difficult sorting through the cruft in Google.

I appreciate your quick response.

EDIT: It's my bad. Google does drill right down to the page you linked when searching "wxWidgets new delete." Unfortunately I was thinking of this as a wxSmith issue and searching "wxSmith new delete" didn't produce anything meaningful in Google or here on the forum. On the upside, maybe now it will.
« Last Edit: March 04, 2012, 09:36:56 pm by BentFX »
Whenever I go to Walmart I always request an intrusive pat-down from the greeter. It looks good on his resume, and it makes us all just a little bit safer.