Fix memory leak in the art provider sample

The list client data must be destroyed not only when closing the
resource browser dialog (see 754f75c1cd (Fix memory leaks in artprov
sample, 2022-01-28) but also whenever the art client is changed.

See #23417, #23418.

(cherry picked from commit 02cba46643a5988db1b0e803e18e2dc1a55d1d21)
This commit is contained in:
PB 2023-04-04 13:42:13 +02:00 committed by Vadim Zeitlin
parent ca4db68006
commit 148cafdcd0
2 changed files with 12 additions and 5 deletions

View File

@ -196,11 +196,7 @@ wxArtBrowserDialog::wxArtBrowserDialog(wxWindow *parent)
wxArtBrowserDialog::~wxArtBrowserDialog() wxArtBrowserDialog::~wxArtBrowserDialog()
{ {
const int itemCount = m_list->GetItemCount(); DeleteListItemData();
// item data are set by the ART_ICON macro
for ( int i = 0; i < itemCount; ++i )
delete reinterpret_cast<wxString*>(m_list->GetItemData(i));
} }
wxSize wxArtBrowserDialog::GetSelectedBitmapSize() const wxSize wxArtBrowserDialog::GetSelectedBitmapSize() const
@ -209,6 +205,14 @@ wxSize wxArtBrowserDialog::GetSelectedBitmapSize() const
return wxSize(size, size); return wxSize(size, size);
} }
void wxArtBrowserDialog::DeleteListItemData()
{
const int itemCount = m_list->GetItemCount();
// item data are set by the ART_ICON macro
for ( int i = 0; i < itemCount; ++i )
delete reinterpret_cast<wxString*>(m_list->GetItemData(i));
}
void wxArtBrowserDialog::SetArtClient(const wxArtClient& client) void wxArtBrowserDialog::SetArtClient(const wxArtClient& client)
{ {
@ -221,6 +225,7 @@ void wxArtBrowserDialog::SetArtClient(const wxArtClient& client)
long sel = m_list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED); long sel = m_list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
if (sel < 0) sel = 0; if (sel < 0) sel = 0;
DeleteListItemData();
m_list->DeleteAllItems(); m_list->DeleteAllItems();
FillBitmaps(img, m_list, index, client, wxSize(16, 16)); FillBitmaps(img, m_list, index, client, wxSize(16, 16));
m_list->AssignImageList(img, wxIMAGE_LIST_SMALL); m_list->AssignImageList(img, wxIMAGE_LIST_SMALL);

View File

@ -34,6 +34,8 @@ private:
wxSize GetSelectedBitmapSize() const; wxSize GetSelectedBitmapSize() const;
void DeleteListItemData();
wxListCtrl *m_list; wxListCtrl *m_list;
wxStaticBitmap *m_canvas; wxStaticBitmap *m_canvas;
wxStaticText *m_text; wxStaticText *m_text;