Memory leaks Topic is solved

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.
Post Reply
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Memory leaks

Post by ONEEYEMAN »

Hi, ALL,

Code: Select all

FieldHeader::FieldHeader(wxWindow *parent) : wxPanel( parent, wxID_ANY )
{
    m_label1 = new wxStaticText( this, wxID_ANY, _( "&Label:" ) );
    m_label = new wxTextCtrl( this, wxID_ANY, wxEmptyString );
    m_label2 = new wxStaticText( this, wxID_ANY, _( "&Position: " ) );
    wxString choices1[] =
    {
        _( "left" )
    };
    m_labelPos = new wxComboBox( this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, 1, choices1, wxCB_DROPDOWN | wxCB_READONLY );
    m_label3 = new wxStaticText( this, wxID_ANY, _( "&Heading:" ) );
    m_heading = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
    m_label4 = new wxStaticText( this, wxID_ANY, wxEmptyString );
    wxString choices2[] =
    {
        _( "left" ),
        _( "right" )
    };
    m_headingPos = new wxComboBox( this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, 2, choices2, wxCB_DROPDOWN | wxCB_READONLY );
    set_properties();
    do_layout();
}

FieldHeader::~FieldHeader(void)
{
}

void FieldHeader::do_layout()
{
    wxBoxSizer *sizer1 = new wxBoxSizer( wxHORIZONTAL );
    wxBoxSizer *sizer2 = new wxBoxSizer( wxVERTICAL );
    wxFlexGridSizer *sizer3 = new wxFlexGridSizer( 2, 2, 5, 5 );
    wxBoxSizer *sizer4 = new wxBoxSizer( wxVERTICAL );
    wxBoxSizer *sizer5 = new wxBoxSizer( wxVERTICAL );
    wxBoxSizer *sizer6 = new wxBoxSizer( wxVERTICAL );
    wxBoxSizer *sizer7 = new wxBoxSizer( wxVERTICAL );
    sizer1->Add( 5, 5, 0, wxEXPAND, 0 );
    sizer2->Add( 5, 5, 0, wxEXPAND, 0 );
    sizer4->Add( m_label1, 0, wxEXPAND, 0 );
    sizer4->Add( 5, 5, 0, wxEXPAND, 0 );
    sizer4->Add( m_label, 0, wxEXPAND, 0 );
    sizer3->Add( sizer4, 0, wxEXPAND, 0 );
    sizer5->Add( m_label2, 0, wxEXPAND, 0 );
    sizer5->Add( 5, 5, 0, wxEXPAND, 0 );
    sizer5->Add( m_labelPos, 0, wxEXPAND, 0 );
    sizer3->Add( sizer5, 0, wxEXPAND, 0 );
    sizer6->Add( m_label3, 0, wxEXPAND, 0 );
    sizer6->Add( 5, 5, 0, wxEXPAND, 0 );
    sizer6->Add( m_heading, 0, wxEXPAND, 0 );
    sizer3->Add( sizer6, 0, wxEXPAND, 0 );
    sizer7->Add( m_label4, 0, wxEXPAND | wxRESERVE_SPACE_EVEN_IF_HIDDEN, 0 );
    sizer7->Add( 5, 5, 0, wxEXPAND, 0 );
    sizer7->Add( m_headingPos, 0, wxEXPAND, 0 );
    sizer3->Add( sizer7, 0, wxEXPAND, 0 );
    sizer2->Add( sizer3, 0, wxEXPAND, 0 );
    sizer2->Add( 5, 5, 0, wxEXPAND, 0 );
    sizer1->Add( 5, 5, 0, wxEXPAND, 0 );
    SetSizer( sizer1 );
//    Layout();
}

void FieldHeader::set_properties ()
{
    m_label4->Hide();
}
Problem is that if I remove the do_layout() code there is no memory leaks.

This is just a simple panel that is added to the wxNotebook and I don't understand what is happening. The page is added as a second page of the wxNotebook.

Could someone shed some light here?

Thank you.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Memory leaks

Post by doublemax »

sizer2 is not added to anything, so it won't be destroyed.
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Memory leaks

Post by ONEEYEMAN »

Thx, doublemax.
Post Reply