In the previous episode we created a memory leak by adding new StaticBitmaps to a Panel without removing the previous StaticBitmap. The Panel keeps track of a growing list of StaticBitmaps which we don’t need – these constitute a ‘leak’ (though they don’t actually cause us any problems). Obviously it is always good programming practice to avoid memory leaks.
We ask the Panel to GetChildren (inherited from Window.GetChildren) and show how many children are being tracked. We then use .Destroy() (inherited from Window.Destory()) to safely clean-up the previous StaticBitmap.
This is one of our Club ShowMeDo Python tutorials, these build upon our free wxPython tutorials which live with our 179 Python tutorials. The source code for this episode is freely available (they all are) further down the video’s page.
Club members get access to 6+ hours of Python tutorials, exercises and walk-throughs with new episodes every week.
If you enjoyed this post, make sure you subscribe to my RSS feed!
“Good job Ian! This video really repays playing over more than once. I like the way that you are building up the code by assembling the parts and explaining them as you go along. wxPython is a lot more complicated than regular Python, and can be confusing if the viewer tries to take in too much as once.” – Jerol Harrington (ShowMeDo Author)
- Exercise 1 for the wxPython Image Viewer – adding a Mirror function
- Menus and Binding for wxPython Image Viewer
- Solution 1 – Walk-through of adding the Mirror Image wxPython function
- Exercise and Solution 2 – Adding the About box and using HTML in wxPython
- wx.FileDialog and CreateStatusBar for our wx Image Viewer