Repository navigation
Fix reference cycle in NotifierMixin._add_listener - #4012
Merged
embray merged 2 commits intoJul 28, 2015
Merged
Conversation
inline "remove" callback contained a reference to self which is held in a __closure__. So the cycle is self._listeners -> self._listeners[n] -> self._listeners[n].__callback__ -> self._listeners[n].__callback__.__closure__ -> self. This is easily fixed by using a WeakValueDict instead, which also helpfully simplifies the code. (The change in io.registry is mostly incidental--it removes an unused variable I found while hunting for reference cycles.)
Merged
Member
Author
|
👐 |
embray
added a commit
that referenced
this pull request
Jul 28, 2015
Fix reference cycle in NotifierMixin._add_listener
embray
added a commit
that referenced
this pull request
Aug 5, 2015
Fix reference cycle in NotifierMixin._add_listener
embray
added a commit
that referenced
this pull request
Aug 7, 2015
Fix reference cycle in NotifierMixin._add_listener
dhomeier
pushed a commit
to dhomeier/astropy
that referenced
this pull request
Aug 11, 2015
embray
added a commit
that referenced
this pull request
Aug 11, 2015
Fix reference cycle in NotifierMixin._add_listener
embray
added a commit
that referenced
this pull request
Aug 11, 2015
Fix reference cycle in NotifierMixin._add_listener
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
NotifierMixin._add_listenerhad a subtle reference cycle--the inline "remove" callback contained a reference to self which is held in a__closure__. So the cycle isself._listeners➡️self._listeners[n]➡️self._listeners[n].__callback__➡️self._listeners[n].__callback__.__closure__➡️self.One possible fix was to change the callback so that it only references the
listenerslist directly, instead of throughself. But a better fix was to use aWeakValueDictinstead, which also helpfully simplifies the code.(The change in io.registry is mostly incidental--it removes an unused variable I found while hunting for reference cycles.)
This partially fixes the failing test in #4001, but it also depends on #4002 to fix reference cycles that occurred in PLY.