[英]Memory leakage due to SetBackgroundBitmap
我已經添加了一個圖像(平鋪)作為繼承自wxPanel的類的背景
在構造函數內部,下面的第二行導致內存泄漏(在調試模式下報告)
wxImage bg(_("images/textures/icobbg8.jpg"), wxBITMAP_TYPE_JPEG);
SetBackgroundBitmap(wxBitmap(bg));
如果我評論SetBackgroundBitmap
內存泄漏不再報告。 注意 - 在調試期間,以及查看調用堆棧后,我在此語句上進行了四舍五入
請告訴我,如何克服內存泄漏。
當構造函數退出時,wxImage bg將被銷毀。 但是,該類仍然存在,仍然需要背景圖像。
嘗試將bg從本地更改為類的屬性。
您應該在析構函數中調用SetBackgroundBitmap(wxNullBitmap)
Class MyPanel:public wxPanel
{
MyPanel(wxWindow* parent, int x, int y, int w, int h);
~MyPanel();
};
MyPanel::~MyPanel()
{
SetBackgroundBitmap(wxNullBitmap); //set null bitmap backgrond, so not
//reference bg to overcome the leak
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.