-
Notifications
You must be signed in to change notification settings - Fork 27k
fix(core): clean up afterRender after it is executed #58119
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
Conversation
We stop tracking `afterRender` hooks as soon as they execute, but their on destroy callbacks stay registered until either the injector is destroyed or the user calls `destroy` manually. This was leading to memory leaks in the `@defer` triggers based on top of `afterRender` when placed inside long-lived views, because the callback would execute, but its destroy logic was waiting for the view to be destroyed. These changes resolve the issue by destroying the `AfterRenderRef` once it is executed.
| this.sequences.delete(sequence); | ||
| // Destroy the sequence so its on destroy callbacks can be cleaned up | ||
| // immediately, instead of waiting until the injector is destroyed. | ||
| sequence.destroy(); |
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.
I was a bit on the fence whether to do it here or afterRun. I did it here, because it seems like the AfterRenderRef isn't intended to have much logic, but to hold the current state.
AndrewKushnir
left a comment
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.
@crisbeto thanks for the fix 👍
|
This PR was merged into the repository by commit 67db430. The changes were merged into the following branches: main, 18.2.x |
We stop tracking `afterRender` hooks as soon as they execute, but their on destroy callbacks stay registered until either the injector is destroyed or the user calls `destroy` manually. This was leading to memory leaks in the `@defer` triggers based on top of `afterRender` when placed inside long-lived views, because the callback would execute, but its destroy logic was waiting for the view to be destroyed. These changes resolve the issue by destroying the `AfterRenderRef` once it is executed. PR Close #58119
|
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. |
We stop tracking
afterRenderhooks as soon as they execute, but their on destroy callbacks stay registered until either the injector is destroyed or the user callsdestroymanually. This was leading to memory leaks in the@defertriggers based on top ofafterRenderwhen placed inside long-lived views, because the callback would execute, but its destroy logic was waiting for the view to be destroyed.These changes resolve the issue by destroying the
AfterRenderRefonce it is executed.