Hi everybody,
I am using DataViewModel and DataViewCtrl extensively. After upgrading to wxPython 4.0.1, I now have objects that don’t get automatically garbage collected, causing memory leaks.
I went through the documentation, in particular wx.dataview.DataViewModel — wxPython Phoenix 4.2.3a1 documentation
I noticed the section about avoiding memory leaks (… you need to decrease the reference count after associating the model with a control…) and the first recommended approach:
musicCtrl = wx.dataview.DataViewCtrl(self, wx.ID_ANY)
musicModel = MyMusicModel()
musicCtrl.AssociateModel(musicModel)
musicModel.DecRef() # avoid memory leak !!
My original code, which I had copied from demo examples, did not include the call to DecRef(). However, my code crashes when I add it.
The second recommended approach (A potentially better way to avoid memory leaks…) is to add a call to get():
musicCtrl = wx.dataview.DataViewCtrl(self, wx.ID_ANY)
musicModel = MyMusicModel()
musicCtrl.AssociateModel(musicModel.get())
When I try this approach, I get an error message: object … has no method get().
Could somebody please shed some light on the correct approach?
Many thanks in advance for your help
AC