Reputation: 6606
I have added a image (tiled) as a background to a class inheriting from wxPanel
Inside the constructor, the second line below is causing memory leakage, (reported in debug mode)
wxImage bg(_("images/textures/icobbg8.jpg"), wxBITMAP_TYPE_JPEG);
SetBackgroundBitmap(wxBitmap(bg));
If i comment the SetBackgroundBitmap
memory leak is no longer reported.
Note - During debugging, and after viewing call stack i rounded on this statement.
Please tell me, how to overcome memory leak.
Upvotes: 0
Views: 183
Reputation: 26
Your should call SetBackgroundBitmap(wxNullBitmap)
in your destructor
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
}
Upvotes: 1
Reputation: 20457
When the constructor exits, the wxImage bg will be destroyed. However, the class still exists and the background image is still needed.
Try changing the bg from a local to an attribute of the class.
Upvotes: 1