In my application, I can create new modules during runtime. A module is an internal application data class, nothing to do with wxWidgets. Each time a new module is created, a wxToggleButton appears on a panel, added to a sizer on that panel. Because I don't know how many buttons will be present during runtime, I bind my event handlers dynamically during runtime. For example :
Code: Select all
void TMyClass::AddModuleButton(void)
{
// create dynamicall a new toggle button
wxToggleButton* NewModuleButton = new wxToggleButton(... the usual stuff...);
// bind a right click menu to the button
NewModuleButton->Bind(wxEVT_CONTEXT_MENU, &TMyClass::OnMyClassContextMenu, this, NewModuleButton->GetId());
// add it to the sizer of my button panel
BoxSizerModules->Add(NewModuleButton, 0, wxEXPAND, 0);
// add a function for a regular left mouse button click on the button
Bind(wxEVT_TOGGLEBUTTON, &TMyClass::OnButtonModuleClick, this, NewModuleButton->GetId());
}
Then I also have a function to delete all the toggle buttons again from the panel again, e.g. when loading a new project file.
Code: Select all
void TMyClass::ClearModules(void)
{
BoxSizerModules->Clear(true); // from wx documentation : if argument delete_windows = true then child windows will also be deleted
}
So by setting the argument as 'true' when calling the sizer clear function, it also deletes the toggle buttons, which is what I want. What I'm wondering now is if the sizer clear function also takes care of the dynamic bindings? More specifically the one attached to the button itself in :
Code: Select all
NewModuleButton->Bind(wxEVT_CONTEXT_MENU, &TMyClass::OnMyClassContextMenu, this, NewModuleButton->GetId());
Does the Sizer->Clear function also automatically Unbind any existing bindings or do I have to do this manually? Do I actually care about this, or is this to be seen as a memory leak?
Using wxWidgets 3.0.5 in C++