-
Notifications
You must be signed in to change notification settings - Fork 10.5k
ui: add CallbackManager for weak-referenced bound-method callbacks #36782
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
base: master
Are you sure you want to change the base?
Conversation
|
I introduced a new bug that wiped the wifi menu's back callback on hide in #36767 avoiding weakref. Weakref seems like the standard approach to callback/event listener setups in Python (our callbacks) @adeebshihadeh. Done well, you won't have to be careful about callbacks keeping a closed Widget in memory |
| def close_dialog(self): | ||
| gui_app.set_modal_overlay(None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have to make everything methods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because WeakSet only supports weakly-referenced bound methods, adding lambdas or plain functions would complicate the design. Supporting bound-method callbacks is sufficient here, and we can use a separate class when we need more flexible callback types for a single-callback case.
|
Does this handle single callbacks added everywhere? For ex. the keyboard using 500K every time you open it from the back callback I assume |
Here is a draft for single callbacks: #36788. Supports bound methods, functions, and lambdas. |
7945f2a to
857ea97
Compare



























Adds a
CallbackManagerthat stores bound-method callbacks as weak references and automatically skips those whose objects have been garbage-collected. This prevents callback lists from keeping UI objects alive and avoids memory leaks.Note: Clients no longer need to manually remove callbacks—dead callbacks are ignored automatically.
A separate PR can add a
SingleCallbackManagerfor places (e.g., dialogs, buttons) that only need single weak-referenced callback.