New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FlatMenu memory leak #2372
Comments
If you think there is a visual memory error @kdschlosser might be able to help you... maybe not. |
you are not forcing a garbage collection. Python is only going to garbage collect when one of these things happens A: it has time to You can force a garbage garbage collection by using the following code. import gc
gc.collect() |
Thank you
…On Thu, Apr 27, 2023, 7:36 PM Kevin Schlosser ***@***.***> wrote:
you are not forcing a garbage collection. Python is only going to garbage
collect when A it has time to or B when you are running out of memory.
You can force a garbage garbage collection by using the following code.
import gc
gc.collect()
—
Reply to this email directly, view it on GitHub
<#2372 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABDTXRAGJUHKDYCFRXCYMF3XDMGIRANCNFSM6AAAAAAW2P5ATY>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Although it doesn't look like a bunch of garbage, it is a problem, indeed,
it is garbage somehow.... Why it is garbage is beyond my knowledge. Ducky
ducky ducky not not club.
On Mon, May 1, 2023, 6:16 AM Metalio Bovinus ***@***.***>
wrote:
… Thank you
On Thu, Apr 27, 2023, 7:36 PM Kevin Schlosser ***@***.***>
wrote:
> you are not forcing a garbage collection. Python is only going to garbage
> collect when A it has time to or B when you are running out of memory.
>
> You can force a garbage garbage collection by using the following code.
>
> import gc
> gc.collect()
>
> —
> Reply to this email directly, view it on GitHub
> <#2372 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ABDTXRAGJUHKDYCFRXCYMF3XDMGIRANCNFSM6AAAAAAW2P5ATY>
> .
> You are receiving this because you commented.Message ID:
> ***@***.***>
>
|
I just ran the script that was provided on Python 3.8 Here is the output
I see garbage collections happening. no issue there. Python 3.10
same deal. No issues with a memory leak. has got to be something specific with the environment the script is running in. OS related problem possibly. I am running Windows 11. |
I'm not sure what this is being applied to... A GUI or an electronic...
This appears to be one of those weird curves that sometimes provide a false
positive. It may be a lazer... It could also be a TDT2 (thermo dynamic
temperature sensor)... Or just a manual... Did it error out on RuntimeError
or DeadObjectError?
I can definitely tell you I'm still alive but I can't tell if an engine is
running. ...so you may be flying behind a tank at 90 mph and stomped on the
error brakes and blew the differential meanwhile 90 other objects behind
probably did the same operation. This is why I hate computer logic. Many
will laugh, but in reality this could be a matter of life or death.
…On Mon, May 1, 2023, 10:18 AM Kevin Schlosser ***@***.***> wrote:
I just ran the script that was provided on Python 3.8
Here is the output
Current 358180 Added 358180
Current 660800 Added 302620
Current 996310 Added 335510
Current 460906 Added -535404
Current 727957 Added 267051
Current 999749 Added 271792
Current 1269499 Added 269750
Current 1539249 Added 269750
Current 1940231 Added 400982
Current 861287 Added -1078944
Current 1131037 Added 269750
Current 1400787 Added 269750
Current 1670537 Added 269750
Current 1940287 Added 269750
Current 1131037 Added -809250
Current 1400787 Added 269750
Current 1670537 Added 269750
Current 1940287 Added 269750
Current 2210037 Added 269750
Current 1402499 Added -807538
Current 1670649 Added 268150
Current 1940399 Added 269750
Current 2210149 Added 269750
Current 2479899 Added 269750
Current 1675817 Added -804082
Current 1940511 Added 264694
Current 2210261 Added 269750
Current 2480011 Added 269750
I see garbage collections happening. no issue there.
Python 3.10
Current 362001 Added 362001
Current 664541 Added 302540
Current 1000113 Added 335572
Current 460693 Added -539420
Current 731896 Added 271203
Current 1006577 Added 274681
Current 1276319 Added 269742
Current 1546061 Added 269742
Current 868067 Added -677994
Current 1137809 Added 269742
Current 1407551 Added 269742
Current 1677293 Added 269742
Current 1947035 Added 269742
Current 1140689 Added -806346
Current 1407551 Added 266862
Current 1677293 Added 269742
same deal. No issues with a memory leak. has got to be something specific
with the environment the script is running in. OS related problem possibly.
I am running Windows 11.
—
Reply to this email directly, view it on GitHub
<#2372 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABDTXRAN6OZXB6G6AOT4PPLXD7H4PANCNFSM6AAAAAAW2P5ATY>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
You're right. Garbage collection is happening, so memory leak was the wrong terminology. But since garbage collection is resource dependent you can't rely on it happening when the system is busy. And yes, you can force it to happen which does fix the issue, but expecting a user to explicitly call for garbage collection after explicitly calling Destroy on an object is a bit much. In my mind calling Destroy on a wx object should destroy that object and all its children. My bigger issue was the eventual exception that gets thrown. That is platform specific as I've been running this code on linux with no problem. So I see two issues with how the code is currently written.
The PR I submitted (#2373) fixes both those issues. It makes the check mark bitmaps class variables for FlatMenuItem instead of instance variables so it isn't unnecessarily creating separate bitmaps for each. And it adds a Destroy method to FlatMenu that calls Clear on the menu to destroy the menu items when the menu is destroyed. I ran into this because the gui program I had that has to dynamically create relatively large context menus would randomly crash on windows sometimes if the user opened the menu multiple times in close succession. Output before:
Output after:
The latter output is more memory efficient and more in line with what I would think a user would expect. |
Operating system: Windows 10
wxPython version & source: self-built
Python version & source: 3.9.6 stock
Description of the problem:
After a FlatMenu object no longer is referenced in the code, it's memory is not cleaned up, I assume because of cyclical references between the FlatMenu and FlatMenuItems. Even if you explicity Destroy and delete the menu, it does not free all the memory.
Separately, a wx.BitMap object is created for the checkbox and radiobox images for each FlatMenuItem that is added. On windows, after a large number of items are created the bitmap creation fails and an exception is thrown.
Traceback (most recent call last):
File "C:\Work\autolab\test\scratch.py", line 15, in
fm.Append(-1, 'item {}'.format(i), kind=wx.ITEM_CHECK)
File "C:\NER\venv\autolab\lib\site-packages\wx\lib\agw\flatmenu.py", line 5476, in Append
newItem = FlatMenuItem(self, id, item, helpString, kind)
File "C:\NER\venv\autolab\lib\site-packages\wx\lib\agw\flatmenu.py", line 4865, in init
self._radioMarkBmp.SetMask(wx.Mask(self._radioMarkBmp, wx.WHITE))
wx._core.wxAssertionError: C++ assertion ""bitmap.IsOk()"" failed at ....\src\msw\bitmap.cpp(1611) in wxMask::Create(): invalid bitmap in wxMask::Create
Since the menu items aren't cleaned up even if the parent menu is destroyed, if a program is dynamically creating context menus with many items, it can hit that limit.
Code Example (click to expand)
The text was updated successfully, but these errors were encountered: