Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I fix a "memory leak of type 'wxPyXmlSubclassFactory *', no destructor found" error from wxPython/wxFormBuilder?

I'm trying to follow this tutorial to quickly make simple GUIs using wxPython and wxFormBuilder.

Using the wxFormBuilder, I created a super simple frame with one vertical layout, one edit text control and a button, which only clears the value of the text control. WxFormBuilder generated the Python code and I just added a few lines to clear the value of the text control when the button is clicked. Here is an image of the stupid simple frame.

simple frame

When I run this file in Python, the GUI does clear the text I type in the text control. When I click on the Frame's close button, I see this:

swig/python detected a memory leak of type 'wxPyXmlSubclassFactory *', no destructor found.

I tried Googling the issue but only found that Python is dynamic enough to not require destructors. I did try out adding the __del__ function, but I still got the same error message.

Ideas for getting rid of that error? I'm using:

  • Python 2.7.6
  • wxPython 3.0.0.0 for Python 2.7
  • wxFormBuilder 3.4.2
  • Windows 7, 32-bit

Thank you so much in advance!

Here's the code I have if anyone needs it:

# -*- coding: utf-8 -*- 

###########################################################################
## Python code generated with wxFormBuilder (version Feb 26 2014)
## http://www.wxformbuilder.org/
##
## PLEASE DO "NOT" EDIT THIS FILE!
###########################################################################

import wx
import wx.xrc

###########################################################################
## Class MyFrame1
###########################################################################

class MyFrame1 ( wx.Frame ):

    def __init__( self, parent ):
        wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 203,155 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )

        self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )

        bSizer1 = wx.BoxSizer( wx.VERTICAL )

        self.edit = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
        bSizer1.Add( self.edit, 1, wx.ALL|wx.EXPAND, 5 )

        self.clearButton = wx.Button( self, wx.ID_ANY, u"Clear", wx.DefaultPosition, wx.DefaultSize, 0 )
        bSizer1.Add( self.clearButton, 1, wx.ALL|wx.EXPAND, 5 )


        self.SetSizer( bSizer1 )
        self.Layout()

        self.Centre( wx.BOTH )

        # Connect Events
        self.clearButton.Bind( wx.EVT_BUTTON, self.clearFunc )

    def __del__( self ):
        pass


    # Virtual event handlers, overide them in your derived class
    def clearFunc( self, event ):
        event.Skip()

class SimpleFrame(MyFrame1):
    def __init__(self,parent):
        MyFrame1.__init__(self,parent)

    def clearFunc(self,event):
        self.edit.SetValue("")

app = wx.App(False)
frame = SimpleFrame(None)
frame.Show(True)
app.MainLoop()
like image 651
Jessica Avatar asked Mar 20 '23 05:03

Jessica


2 Answers

I keep getting the same error with the latest version (3.0.0). No new version's been released since. No need to worry though. Expect to see a fix sometime soon.

Take a look at the last post here

like image 162
user2963623 Avatar answered Mar 22 '23 18:03

user2963623


From what I was able to tell, this is a fairly harmless bug with wxPython, but it sounds like the author has a fix that may or may not have been released:

http://trac.wxwidgets.org/changeset/75542

Don't know much about wxPython, but looking at the timestamps of the release of version 3.0.0 (Dec) and of the change I just linked (Jan), it looks like it might not be in the version you have. Have you tried updating wxPython? Worst case scenario, you could try making the linked code changes yourself if you're feeling brave. Good luck!

like image 20
Nacho Avatar answered Mar 22 '23 20:03

Nacho