-
Notifications
You must be signed in to change notification settings - Fork 272
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
Use weakref.proxy where parent=self. #2223
Conversation
Co-authored-by: Lukas Nickel <lukas.nickel@tu-dortmund.de> Co-authored-by: Rune Dominik <rune.dominik@tu-dortmund.de>
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Nice! |
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.
Very good catch!
While I think it is the right thing to do, this needs a better usability. Can we somehow do this automatically in Component.__init__
? E.g. do super().__init__(parent=weakref.proxy(parent))
?
Any downside to this?
didn't think of that, I will check if that works. |
what doesn't get proxied is when calling But I still like the two-line change much more and will implement it. This will then fix the symptoms for quite some time, until we can fix the root cause. |
@nbiederbeck Ok, but special-casing that only in |
I didn't even want to special-case that, just leave it as is. Still has a great improvement vs. master |
Here are the changes from I need to partially withdraw my earlier comment. |
This reverts commit 2ddb4fc.
71c7e0f
to
f24bb1e
Compare
Still, using weakref is the correct solution I think. So we should add it also to the |
Fixes #2218, where the CI fails with OOM, by allowing python to garbage-collect Tools after tests. Co-authored-by: Lukas Nickel <lukas.nickel@tu-dortmund.de> Co-authored-by: Rune Dominik <rune.dominik@tu-dortmund.de>
done |
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.
nice fix! This is much better than requiring component devs to understand that they need a weakref.
We dug a little to Fix #2218.
We found that the garbage collector of python does not clean up after tests have run. This seems to be the case because the tools specify
parent=self
, and when the tools are out of scope, somehow their children stay in memory and thus the references to the tools via theparent
are still valid, which is why it cannot be garbage-collected.We replaced
parent=self
withparent=weakref.proxy(self)
, which does not increment the reference counter. This makes it possible to be collected once the tools are out of scope.We needed to fix a single test, where before we asserted that the parent of a children is the object itself, which is no longer valid, because it now is a Proxy.
These changes have two great outcomes: the total test time decreases in fact a little, and the total memory consumption is decreased more than 50% !
The root cause is probably in the configsystem, where we need the references to the parents. Changing this would likely fix the problem, and not just the symptoms.
The black line in the plot is this branch, the blue line is the current master.
Co-authored-by: Lukas Nickel lukas.nickel@tu-dortmund.de
Co-authored-by: Rune Dominik rune.dominik@tu-dortmund.de