-
Notifications
You must be signed in to change notification settings - Fork 25.6k
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
fix(upgrade): fix memory leaks when the component is destroyed #39921
Conversation
$$$angularInjectorController
Currently we're storing the real injector on the element inside the `ParentInjectorPromise` and its `resolve()` method. This causes a memory leak if we don't remove the reference when the component is destroyed. We also setup the `$destroy` listener and never release it, the problem is that this listener captures `this`, as long as there is a reference, `this` will not be GC'd. PR Close #39911
@arturovt, is this PR ready for review (I've noticed you have been pushing new commits recently)? |
Yep, you can start reviewing. |
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.
LGTM but it has been a while since I look at ngUpgrade code.
@gkalpak will probably have more to say :-)
@petebacondarwin @gkalpak gentlemen just for your information: this is AFTER Basically, the |
Previously, due to the way the AngularJS and Angular clean-up processes interfere with each other when removing an AngularJS element that contains a downgraded Angular component, the data associated with the host element of the downgraded component was not removed. This data was kept in an internal AngularJS cache, which prevented the element and component instance from being garbage-collected, leading to memory leaks. This commit fixes this by ensuring the element data is explicitly removed when cleaning up a downgraded component. NOTE: This is essentially the equivalent of angular#26209 but for downgraded (instead of upgraded) components. Fixes angular#39911 Closes angular#39921
Previously, due to the way the AngularJS and Angular clean-up processes interfere with each other when removing an AngularJS element that contains a downgraded Angular component, the data associated with the host element of the downgraded component was not removed. This data was kept in an internal AngularJS cache, which prevented the element and component instance from being garbage-collected, leading to memory leaks. This commit fixes this by ensuring the element data is explicitly removed when cleaning up a downgraded component. NOTE: This is essentially the equivalent of angular#26209 but for downgraded (instead of upgraded) components. Fixes angular#39911 Closes angular#39921
Previously, due to the way the AngularJS and Angular clean-up processes interfere with each other when removing an AngularJS element that contains a downgraded Angular component, the data associated with the host element of the downgraded component was not removed. This data was kept in an internal AngularJS cache, which prevented the element and component instance from being garbage-collected, leading to memory leaks. This commit fixes this by ensuring the element data is explicitly removed when cleaning up a downgraded component. NOTE: This is essentially the equivalent of angular#26209 but for downgraded (instead of upgraded) components. Fixes angular#39911 Closes angular#39921
Previously, due to the way the AngularJS and Angular clean-up processes interfere with each other when removing an AngularJS element that contains a downgraded Angular component, the data associated with the host element of the downgraded component was not removed. This data was kept in an internal AngularJS cache, which prevented the element and component instance from being garbage-collected, leading to memory leaks. This commit fixes this by ensuring the element data is explicitly removed when cleaning up a downgraded component. NOTE: This is essentially the equivalent of angular#26209 but for downgraded (instead of upgraded) components. Fixes angular#39911 Closes angular#39921
Previously, due to the way the AngularJS and Angular clean-up processes interfere with each other when removing an AngularJS element that contains a downgraded Angular component, the data associated with the host element of the downgraded component was not removed. This data was kept in an internal AngularJS cache, which prevented the element and component instance from being garbage-collected, leading to memory leaks. This commit fixes this by ensuring the element data is explicitly removed when cleaning up a downgraded component. NOTE: This is essentially the equivalent of angular#26209 but for downgraded (instead of upgraded) components. Fixes angular#39911 Closes angular#39921
Thx for working on this, @arturovt 👍 While reviewing your PR, it thought it was "suspicious" that we had to clean up stuff that would normally be cleaned up automatically. So I dug deeper to understand why it wasn't being clean up. In a nutshell, it happens because (under some circumstances) Angular will remove the component host element from the DOM before AngularJS has a chance to clean it up. See here for more details. Based on the above, I have created #39965 with an alternative fix, which I think is simpler and more consistent with how things would work in a pure AngularJS app. I would appreciate it if you could take a look and let me know what you think? BTW, you can also grab the build artifacts from my PR (see here for more info) and use them in a sample app in order to verify the fix. |
I've played with your changes and it seems to work (the adapter is released successfully). Nice job! |
Awesome! Thx for checking, @arturovt ❤️ |
Previously, due to the way the AngularJS and Angular clean-up processes interfere with each other when removing an AngularJS element that contains a downgraded Angular component, the data associated with the host element of the downgraded component was not removed. This data was kept in an internal AngularJS cache, which prevented the element and component instance from being garbage-collected, leading to memory leaks. This commit fixes this by ensuring the element data is explicitly removed when cleaning up a downgraded component. NOTE: This is essentially the equivalent of angular#26209 but for downgraded (instead of upgraded) components. Fixes angular#39911 Closes angular#39921
…39965) Previously, due to the way the AngularJS and Angular clean-up processes interfere with each other when removing an AngularJS element that contains a downgraded Angular component, the data associated with the host element of the downgraded component was not removed. This data was kept in an internal AngularJS cache, which prevented the element and component instance from being garbage-collected, leading to memory leaks. This commit fixes this by ensuring the element data is explicitly removed when cleaning up a downgraded component. NOTE: This is essentially the equivalent of #26209 but for downgraded (instead of upgraded) components. Fixes #39911 Closes #39921 PR Close #39965
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
PR Checklist
PR Type
What is the current behavior?
Issue Number: #39911
Does this PR introduce a breaking change?