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:
parent
ca4db68006
commit
148cafdcd0
@ -196,11 +196,7 @@ wxArtBrowserDialog::wxArtBrowserDialog(wxWindow *parent)
|
||||
|
||||
wxArtBrowserDialog::~wxArtBrowserDialog()
|
||||
{
|
||||
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));
|
||||
DeleteListItemData();
|
||||
}
|
||||
|
||||
wxSize wxArtBrowserDialog::GetSelectedBitmapSize() const
|
||||
@ -209,6 +205,14 @@ wxSize wxArtBrowserDialog::GetSelectedBitmapSize() const
|
||||
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)
|
||||
{
|
||||
@ -221,6 +225,7 @@ void wxArtBrowserDialog::SetArtClient(const wxArtClient& client)
|
||||
long sel = m_list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
|
||||
if (sel < 0) sel = 0;
|
||||
|
||||
DeleteListItemData();
|
||||
m_list->DeleteAllItems();
|
||||
FillBitmaps(img, m_list, index, client, wxSize(16, 16));
|
||||
m_list->AssignImageList(img, wxIMAGE_LIST_SMALL);
|
||||
|
@ -34,6 +34,8 @@ private:
|
||||
|
||||
wxSize GetSelectedBitmapSize() const;
|
||||
|
||||
void DeleteListItemData();
|
||||
|
||||
wxListCtrl *m_list;
|
||||
wxStaticBitmap *m_canvas;
|
||||
wxStaticText *m_text;
|
||||
|
Loading…
Reference in New Issue
Block a user