Possible memory leak when opening QMenu in PyQt5
Alexander Stamatov
alexander.stamatov at outlook.com
Thu May 14 13:08:48 BST 2026
Hello, I am observing a large consistent increase in RAM every time a nested QMenu is opened in my PyQt5 application.
Even with a simplified example using a nested menu and no external images, the RAM usage grows with each interaction and does not appear to be reclaimed. If you do not nest QMenus, nothing will happen, and the memory will be deallocated as expected. I have attached a minimal reproducible example and demonstrating the problem, here is the link to a video demonstrating it on my pc: https://drive.google.com/file/d/1pfactub-1R-gPSmARAOmKe9RgujfQdbx/view?usp=sharing
To reproduce: Run the script, Double-Middle-click the blue square, select one of the options from the inner menu and repeat a few times. Finally, observe the console output; the RAM usage increases on each open/close cycle, while the Qt object count remains constant.
Environment: Python 3.13.9, PyQt5 version: 5.15.11, Operating System: Windows 11 Pro.
Is this expected behavior due to internal Qt caching, or is there a specific way to ensure these resources are released?
Thank you for your time and help.
Best regards, Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20260514/dc83c495/attachment.htm>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: PyQt5_Memory_Leak_Menu_Rename_To_py.txt
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20260514/dc83c495/attachment.txt>
More information about the PyQt
mailing list