The underlying C++ wxBoxSizer is not automatically freed when the corresponding Python object disappears (reaches a reference count of zero), unless the sizer has been added to another sizer or set as the sizer for a wxWindow with SetSizer. The attached sample demonstrates this: a memory leak is reported when the program ends. Calling Destroy() on the sizer prevents the leak, but this is undocumented.
It seems to me that the Python wxSizer's __del__ method ought to destroy the C++ object. Also, if wxSizer needs to be Destroy()-ed unless its window or parent sizer does so, then both that fact and the Destroy method should be documented.
I am using wxPython 2.3.2.1, Python 1.5.2, on MS Windows 98SE.
David
P.S. the reason I have an extra, unused sizer in the first place is that
I have a subclass of wxDialog which I further subclass to create several variants on the same dialog. My base class's __init__ method creates a wxBoxSizer and passes it to a more_buttons method. If more_buttons returns true, then the sizer is added to the main sizer for the dialog. That way, the variants can override more_buttons to add controls to the dialog. I can rewrite my code so that the sizer isn't created unless one of the subclasses actually adds more controls.
leak.py (470 Bytes)