If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
rkamarowski
Knows some wx things
Posts: 34 Joined: Fri Jan 14, 2022 5:54 pm
Post
by rkamarowski » Sun Aug 14, 2022 6:04 pm
Windows 11
Visual Studio 2022
C++
wxWidgets 3.2.0
I have the following code in my wxFrame:
If I close the app by clicking the 'X' in the upper right hand corner of the window VS2022 is reporting memory leaks. If I close app using the red Stop Debugging button there are no memory leaks reported. If I comment out the above line of code no leaks are reported either way the app is closed.
Am I having memory leaks, and why?
Thank you,
Bob K.
doublemax
Moderator
Posts: 19164 Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2
Post
by doublemax » Sun Aug 14, 2022 7:45 pm
That's not enough code. If the menu is added to a wxMenuBar, and that wxMenuBar is attached to the wxFrame, there should be no memory leak.
Check the "minimal" sample that comes with the wxWidgets source code for reference.
Use the source, Luke!
rkamarowski
Knows some wx things
Posts: 34 Joined: Fri Jan 14, 2022 5:54 pm
Post
by rkamarowski » Sun Aug 14, 2022 8:48 pm
Code: Select all
#include "PMainFrame.h"
using namespace pWidgets;
PMainFrame::PMainFrame()
: wxFrame(NULL, wxID_ANY, "EES Photography", wxPoint(10,10))
{
OnInit();
}
void PMainFrame::OnInit()
{
Bind(wxEVT_MENU, &PMainFrame::OnAbout, this, TEXT_ABOUT);
Bind(wxEVT_MENU, &PMainFrame::OnExit, this, TEXT_EXIT);
SetMinSize(wxSize(800, 600));
SetSize(100, 100, 900, 700);
Center(wxBOTH);
wxMenu* fileMenu = new wxMenu();
fileMenu->AppendSeparator();
fileMenu->Append(TEXT_EXIT, wxT("E&xit"), wxT("Exit application"));
wxMenu* routineMenu = new wxMenu();
routineMenu->Append(ROUTINE_EDIT, wxT("&Edit routine"),
wxT("Edit routine."));
routineMenu->Append(ROUTINE_EXECUTE, wxT("&Run routine"),
wxT("Run routine."));
wxMenu* aboutMenu = new wxMenu;
aboutMenu->Append(TEXT_ABOUT, wxT("&About"));
wxMenuBar* menuBar = new wxMenuBar(wxMB_DOCKABLE);
menuBar->Append(fileMenu, wxT("&File"));
menuBar->Append(aboutMenu, wxT("&About"));
SetMenuBar(menuBar);
}
void PMainFrame::OnExit(wxCommandEvent& event)
{
Close(true);
}
doublemax
Moderator
Posts: 19164 Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2
Post
by doublemax » Sun Aug 14, 2022 9:35 pm
You're not adding routineMenu to the menubar.
Use the source, Luke!
rkamarowski
Knows some wx things
Posts: 34 Joined: Fri Jan 14, 2022 5:54 pm
Post
by rkamarowski » Mon Aug 15, 2022 3:41 pm
Ugh... As always, thank you doublemax. Hopefully next time it will be something more interesting
Bob K.