Skip to content
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

Automatic unregistering of BindableProperty objects #4122

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

andybayer
Copy link

First draft to fix the issue reported in #4109.

Replaces the values in the binding.bindable_properties data structure, which acts as a "registry" for available bindable properties, with weakref.finalize objects. Previously, there was a permanent reference to the owner of the BindableProperty, which was never cleared unless explicitly removed with binding.remove.

I also added some very basic tests for this behavior. You may need to refactor these slightly.

What I did not test, and what in theory should still be a problem, is when 2 models have bindable properties and one model binds to a value of the other. Then permanent references to the models are kept in binding.bindings, which are never automatically cleaned up.

Andreas Bayer added 2 commits December 18, 2024 11:56
@falkoschindler
Copy link
Contributor

Thanks a lot for this pull request, @andybayer!

I'm just wondering: Have you tried replacing the Dict with a Set, as mentioned in #4109 (comment)? Wouldn't it avoid the need for weakrefs?

@falkoschindler falkoschindler added the bug Something isn't working label Dec 18, 2024
@andybayer
Copy link
Author

Yes, I tried replacing the Dict with a Set and everything worked as expected. I started to implement this fix, but suddenly I thought that the Set also needs to be cleaned up, or else deleted items will clutter it up. So I thought an automatic cleanup action was needed.

I added the cleanup action as a new value to the Dict. Actually, I think it's not the best design because the Dict now has two jobs. It serves as a quick lookup of whether an object-attribute-pair is a BindableProperty and also as a storage for abortable cleanup actions. Perhaps we should not store a reference to the cleanup action at all, since it does no harm to run it after the object has already been manually removed with binding.remove?

@andybayer
Copy link
Author

So what would you suggest as the next step(s) @falkoschindler?

Shall I change something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants