• Could not connect to Twitter

Building a wxPython Image Viewer – 8th episode

For the 8th episode in the series we look at Avoiding wx Memory Leaks with .Destroy() to teach some good programming practice.

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.

“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)

Please share:
  • DZone
  • del.icio.us
  • Reddit
  • Furl
  • Ma.gnolia
  • email
  • StumbleUpon
  • Technorati
  • TwitThis
  • Slashdot
If you enjoyed this post, make sure you subscribe to my RSS feed!

Related posts:

  1. Exercise 1 for the wxPython Image Viewer – adding a Mirror function
  2. Menus and Binding for wxPython Image Viewer
  3. Solution 1 – Walk-through of adding the Mirror Image wxPython function
  4. Exercise and Solution 2 – Adding the About box and using HTML in wxPython
  5. wx.FileDialog and CreateStatusBar for our wx Image Viewer

Comments are closed.