Skip to content

fix: Clean QMenuItemAction parent on Application destroy - #290

Merged
tlambert03 merged 2 commits into
pyapp-kit:mainfrom
Czaki:fix_action_alive
Nov 20, 2026
Merged

tlambert03 merged 2 commits into
pyapp-kit:mainfrom
Czaki:fix_action_alive

Conversation

@Czaki

@Czaki Czaki commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

See napari/napari#9867

In napari test suite, each test has its own application instance. But there is one QApplication for all.

It led to thousands of QMenuItemAction objects living along tests, slowing down the test suite by making gc.collect() more expensive.

This PR is adding a callback to app.destroyed to remove the parent from QMenuItemAction to allow it to be destroyed.

Maybe it should go to QCommandAction.

@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.49%. Comparing base (ace34a6) to head (8a1e717).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #290   +/-   ##
=======================================
  Coverage   99.49%   99.49%           
=======================================
  Files          31       31           
  Lines        1971     1975    +4     
=======================================
+ Hits         1961     1965    +4     
  Misses         10       10           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tlambert03 tlambert03 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tlambert03 tlambert03 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it should go to QCommandAction

your call. do you want this merged as is? or do you want time to think about it

@Czaki

Czaki commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

For napari, this PR is enough. The QMenuItemAction is the only place where app-model set parentship.
moving it upper only will save other potential users who don't perform proper cleanup steep.

So maybew merge it as it is.

@tlambert03
tlambert03 merged commit 684092d into pyapp-kit:main Nov 20, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants