Win10 memory leak / GDI Object issue

810 views
Skip to first unread message

Nev

unread,
Jul 3, 2019, 12:24:56 PM7/3/19
to wxPython-users
Hi,
First-time posting, so apologies in advance for any etiquette failings.

I have a wx GUI in which the user opens and closes various AGW-managed notebooks. After extended use the program crashes, which I've tracked-down to hitting the Windows GDI Object limit. My program has no need for this many objects - it just seems they're just not being cleaned-up when panes and notebooks are closed. 

My wx version is "4.0.6 msw (phoenix) wxWidgets 3.0.5" (Python 3.7.3). I've also seen the same behavior on wx 4.0.3 (Python 3.6.7).

I've tried to hunt online for solutions, and found a couple of references to similar problems, such as these from 2013 (I'm not a software developer by training, so this is really pushing my limits):

It's not clear to me if this is the same issue, and if it is, whether it was ever successfully fixed. Maybe I'm just closing the gui elements in the wrong way, and causing the mess myself?!

I've attached an example code which shows the problem and also for convenience reports memory and GDI usage in the statusbar. When you run it, go to the Options menu and just create and then delete the panes, and watch the GDI usage rise.


Many thanks for any help you can provide, and please let me know if there's any additional info I should have provided.

Nev.
GDI demo.py

Steve Barnes

unread,
Jul 4, 2019, 12:57:03 AM7/4/19
to wxpytho...@googlegroups.com

Nev,

 

From a quick look at your demo each time that you are creating a pane you are creating a whole new notebook then on closing the pane you ask AUI Manager to destroy the pane but this leaves the notebook, generally you would normally create the Notebook once, use it adding and removing panes as needed, then destroy it at the end of the program. BTW have you thought of hiding and showing panes rather than creating/deleting – this tends to be faster and have less resource issues (as the resource count is fixed).

 

Steve

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/94576b15-ef4d-4f19-babb-3cd2d012b629%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nev

unread,
Jul 4, 2019, 2:32:51 AM7/4/19
to wxPython-users

On Thursday, July 4, 2019 at 6:57:03 AM UTC+2, Gadget Steve wrote:

Nev,

 

From a quick look at your demo each time that you are creating a pane you are creating a whole new notebook then on closing the pane you ask AUI Manager to destroy the pane but this leaves the notebook, generally you would normally create the Notebook once, use it adding and removing panes as needed, then destroy it at the end of the program. BTW have you thought of hiding and showing panes rather than creating/deleting – this tends to be faster and have less resource issues (as the resource count is fixed).

 

Steve 


Thanks for the suggestions, Steve. Yes, I see now that a lot of my initial choices were rather inefficient. With more re-use of existing objects, and more show/hide rather than create/destroy, I think I could avoid this problem for far longer. Unfortunately in the short term, I'm mostly stuck with what I currently have.

In the demo, I think destroying the pane is also destroying the notebook itself (actually, isn't the notebook itself the pane?). At least, if I do a notebook.Destroy() before the ClosePane, the result is the same.

I've found that if I swap-out a vanilla wx.Notebook instead of the wx.lib.agw.aui.AuiNotebook, the problem goes away, so I think this is a reproducable GDI object leak in the AuiNotebook. Just not sure if it's worth posting a bug report? It seems to have been there for years, but I guess it only causes a problem for people who make bad design choices!

Steve Barnes

unread,
Jul 5, 2019, 12:53:50 AM7/5/19
to wxpytho...@googlegroups.com

 

 

From: wxpytho...@googlegroups.com <wxpytho...@googlegroups.com> On Behalf Of Nev
Sent: 04 July 2019 07:33
To: wxPython-users <wxpytho...@googlegroups.com>
Subject: Re: [wxPython-users] Win10 memory leak / GDI Object issue

 


[Steve Barnes] <Snip>

 

Thanks for the suggestions, Steve. Yes, I see now that a lot of my initial choices were rather inefficient. With more re-use of existing objects, and more show/hide rather than create/destroy, I think I could avoid this problem for far longer. Unfortunately in the short term, I'm mostly stuck with what I currently have.

 

In the demo, I think destroying the pane is also destroying the notebook itself (actually, isn't the notebook itself the pane?). At least, if I do a notebook.Destroy() before the ClosePane, the result is the same.

 

I've found that if I swap-out a vanilla wx.Notebook instead of the wx.lib.agw.aui.AuiNotebook, the problem goes away, so I think this is a reproducable GDI object leak in the AuiNotebook. Just not sure if it's worth posting a bug report? It seems to have been there for years, but I guess it only causes a problem for people who make bad design choices!

 

[Steve Barnes]

Nev,

I would say that it is worth reporting, not necessarily so much in the hope of it getting fixed as to record possible mitigating approaches for anybody else hitting this problem.

 

The root cause may well be that if you are frequently deleting and recreating lots of GUI objects then you may hit the GUI limit before they are all garbage collected, (deleting a top level object just reduces the reference instance count of the child objects to zero and lets gc take care of actually removing them.

 

Steve

Reply all
Reply to author
Forward
0 new messages