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

Add an unbind_extension_point function #546

Merged
merged 4 commits into from
Mar 23, 2023
Merged

Conversation

mdickinson
Copy link
Member

@mdickinson mdickinson commented Mar 22, 2023

This PR adds an unbind_extension_point function that reverses the effects of bind_extension_point. In particular, unbind_extension_point removes references to the target HasTraits object from global state, allowing that object to be garbage collected in the usual way. (Previously, those references would live until the end of the process.)

Detailed changes

  • New unbind_extension_point function (exported via envisage.api), with parameters exactly matching those of bind_extension_point. This undoes listener changes, and removes the binding from the global ExtensionPointBinding._bindings dictionary.
  • New private ExtensionPointBinding._unbind method that undoes listener changes. The _initialize method has been renamed to _bind to match.
  • Creation of an ExtensionPointBinding object no longer modifies the global ExtensionPointBinding._bindings dictionary; instead, that mutation of global state is done in bind_extension_point. (At some point in the future, we may want to move this global state somewhere else - perhaps onto the extension registry.)
  • ExtensionPointBinding._bindings is now a regular Python dict instead of a WeakKeyDictionary: the weak reference functionality never worked in the first place because our dictionary values had a strong reference to the corresponding keys, so there's no need for the additional complication introduced by the use of a WeakKeyDictionary.

Fixes #97

Copy link
Contributor

@corranwebster corranwebster left a comment

Choose a reason for hiding this comment

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

LGTM

@mdickinson mdickinson merged commit 970dfba into main Mar 23, 2023
@mdickinson mdickinson deleted the unbind-extension-point branch March 23, 2023 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bind_extension_point prevents object garbage collection
2 participants