#14670: GDI/Memory Leak in wx.AuiNotebook

12 views
Skip to first unread message

wxTrac

unread,
Sep 18, 2012, 1:25:42 PM9/18/12
to wx-...@googlegroups.com
Ticket URL: <http://trac.wxwidgets.org/ticket/14670>

#14670: GDI/Memory Leak in wx.AuiNotebook
-------------------------+--------------------------------------------------
Reporter: davidsamson | Owner:
Type: defect | Status: new
Priority: normal | Milestone:
Component: wxAui | Version: 2.8.12
Keywords: GDI Leak | Blockedby:
Patch: 0 | Blocking:
-------------------------+--------------------------------------------------
I have a fix for a GDI/Memory leak in wx.AuiNotebook. The leak arises
from inheriting from wx.EvtHandler and not properly destroying it. It
will block the destructor of the sub-class and therefore keep the python
object and all it's members in memory. (So, it's also a memory leak.)

The fix is to add the following method to class AuiManager in
framemanager.py


{{{
def destroy(self):
try:
wx.EvtHandler.Destroy(self)
except:
pass

}}}

and add this method to class AuiNotebook in auibook.py:


{{{
def __del__(self):
self._mgr.destroy()
wx.PyPanel.__del__()

}}}

Note that this same method is used elsewhere in wx for objects that
inherit from EvtHandler. Also, I would imagine that any other classes
that use AuiManager will need this fix as well.

The changed files auibook.py and framemanager.py go here in the python
tree:

Python27\Lib\site-packages\wx-2.8-msw-unicode\wx\lib\agw\aui

You can test this by creating and destroying an AuiNotebook and watching
the GDI count in task manager.


--
Ticket URL: <http://trac.wxwidgets.org/ticket/14670>

wxTrac

unread,
Sep 18, 2012, 3:21:00 PM9/18/12
to wx-...@googlegroups.com
Ticket URL: <http://trac.wxwidgets.org/ticket/14670#comment:1>

#14670: GDI/Memory Leak in wx.AuiNotebook
-------------------------------------------------------------+--------------
Reporter: davidsamson | Owner:
Type: defect | Status: infoneeded_new
Priority: normal | Milestone:
Component: AGW | Version: 2.9-svn
Keywords: wx.lib.agw framemanager auinotebook memory leak | Blockedby:
Patch: 0 | Blocking:
-------------------------------------------------------------+--------------
Changes (by infinity77):

* keywords: GDI Leak => wx.lib.agw framemanager auinotebook memory leak
* status: new => infoneeded_new
* version: 2.8.12 => 2.9-svn
* component: wxAui => AGW


Comment:

Hi,

please test again against the SVN version of AGW, as this bug has
nothing to do with wxAUI. If the module lives in wx.lib, the bug report is
wxPython-specific. If it lives in wx.lib.agw, the it is AGW specific.

Something similar to your patch was added a while back in SVN to fix a
similar "memory leak".


--
Ticket URL: <http://trac.wxwidgets.org/ticket/14670#comment:1>

wxTrac

unread,
Nov 12, 2013, 11:14:22 AM11/12/13
to wx-...@googlegroups.com
Ticket URL: <http://trac.wxwidgets.org/ticket/14670#comment:2>

#14670: GDI/Memory Leak in wx.AuiNotebook
-------------------------------------------------------------+--------------
Reporter: davidsamson | Owner:
Type: defect | Status: new
Priority: normal | Milestone:
Component: AGW | Version: 2.9-svn
Keywords: wx.lib.agw framemanager auinotebook memory leak | Blockedby:
Patch: 0 | Blocking:
-------------------------------------------------------------+--------------
Changes (by tbrizzi):

* status: infoneeded_new => new


Comment:

Hi,

I've attached to this ticket a demonstrator correcting GDI resources
management of AGW's AuiManager containing auto-generated AuiNotebooks.

This demonstrator displays a AuiNotebook widget and each page of this
notebook contains an AuiManager displaying several panels. By default, GDI
resources consumed by this kind of page are never released when it
contains panels merged inside a notebook.

The solution was to overload the Destroy method of the view displaying the
panels the following way :


{{{
class MyView(wx.Panel):

def __init__(self, *args, **kwargs):
super(MyView, self).__init__(*args, **kwargs)

# create the layout
self.manager = MyManager(self, agwFlags=aui.AUI_MGR_DEFAULT)

...

def Destroy(self):
# release resources occupied by AuiManager
# objects relative to each AuiNotebook
for nb in self.manager.GetNotebooks() :
nb._mgr.UnInit()
nb._mgr.Destroy()
nb.Destroy()

# release resources occupied by the AuiManager
# relative to the notebook containg this page
self.manager.UnInit()
self.manager.Destroy()

super(MyView, self).Destroy()
}}}

Please, close the ticket if it has been effectively corrected in a stable
version of AGW.

Regards.


--
Ticket URL: <http://trac.wxwidgets.org/ticket/14670#comment:2>
Reply all
Reply to author
Forward
0 new messages