Search code examples
c++cmemorygarbage-collectionwxwidgets

wxWidgets has some sort of garbage collector?


#include <wx/wx.h>

class MyApp : public wxApp
{
    virtual bool OnInit();
};

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit()
{
    wxFrame *frame = new wxFrame(NULL, -1, _("Hello World"), wxPoint(50, 50),
                                  wxSize(450, 350));       
    frame->Show(true);
    return true;
}

This code works fine and it is the kind of code if seen out there. I allocate a wxFrame on the heap and I never worry about the memory, does wxWidgets collects it's own garbage?


Solution

  • AFAIK, this is how you should handle windows with wxWidgets. The reference says that you particularly must not delete them, and that you can request them to be destroyed with wxWindow::Destroy. The default behavior of a frame closed by user action is that the frame is destroyed.

    There is no garbage collection as such (e.g a new wxString() will leak unless deleted), but the memory for some classes will be automatically managed by the library.

    wxWidgets window deletion overview