Win10 memory leak / GDI Object issue

classic Classic list List threaded Threaded
4 messages Options
Nev
Reply | Threaded
Open this post in threaded view
|

Win10 memory leak / GDI Object issue

Nev
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.

--
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 [hidden email].
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.

GDI demo.py (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

RE: Win10 memory leak / GDI Object issue

GadgetSteve

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

 

From: [hidden email] <[hidden email]> On Behalf Of Nev
Sent: 03 July 2019 12:15
To: wxPython-users <[hidden email]>
Subject: [wxPython-users] Win10 memory leak / GDI Object issue

 

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.

--
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 [hidden email].
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.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/VI1PR03MB447909709E0FAD252F45693E9BFA0%40VI1PR03MB4479.eurprd03.prod.outlook.com.
For more options, visit https://groups.google.com/d/optout.
Nev
Reply | Threaded
Open this post in threaded view
|

Re: Win10 memory leak / GDI Object issue

Nev

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!

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/f1897cc1-4ace-4b02-b5c3-d56da0ffd1c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

RE: Win10 memory leak / GDI Object issue

GadgetSteve

 

 

From: [hidden email] <[hidden email]> On Behalf Of Nev
Sent: 04 July 2019 07:33
To: wxPython-users <[hidden email]>
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

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/VI1PR03MB4479042A05EA7E0A7D05F7729BF50%40VI1PR03MB4479.eurprd03.prod.outlook.com.
For more options, visit https://groups.google.com/d/optout.