Skip to content

fix(core): do not retain dynamically compiled components and modules #42003

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

Closed
wants to merge 1 commit into from

Conversation

JoostK
Copy link
Member

@JoostK JoostK commented May 8, 2021

The JIT compiler has a mapping from component to the owning NgModule
and tracks whether a certain NgModule class has been verified; these
maps causes any JIT compiled component and NgModule to be retained even
if they are no longer referenced from anywhere else. This commit
switches the maps to WeakMap to allow garbage collecting any
components and NgModules that are no longer referenced elsewhere.

Fixes #19997

The JIT compiler has a mapping from component to the owning NgModule
and tracks whether a certain NgModule class has been verified; these
maps causes any JIT compiled component and NgModule to be retained even
if they are no longer referenced from anywhere else. This commit
switches the maps to `WeakMap` to allow garbage collecting any
components and NgModules that are no longer referenced elsewhere.

Fixes angular#19997
@JoostK JoostK added memory leak Issue related to a memory leak area: core Issues related to the framework runtime target: patch This PR is targeted for the next patch release labels May 8, 2021
@ngbot ngbot bot modified the milestone: Backlog May 8, 2021
@google-cla google-cla bot added the cla: yes label May 8, 2021
@JoostK JoostK marked this pull request as ready for review May 8, 2021 15:28
@JoostK JoostK added the action: review The PR is still awaiting reviews from at least one requested reviewer label May 8, 2021
@pullapprove pullapprove bot requested a review from mhevery May 8, 2021 15:28
@JoostK JoostK requested review from AndrewKushnir and removed request for mhevery May 8, 2021 15:29
@JoostK
Copy link
Member Author

JoostK commented May 8, 2021

Note: there is precedent for using WeakMap in @angular/core in View Engine code:

const DEFINITION_CACHE = new WeakMap<any, Definition<any>>();

so this usage here should not require additional polyfills.

Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

@JoostK thanks for the fix 👍

@AndrewKushnir AndrewKushnir added action: presubmit The PR is in need of a google3 presubmit and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels May 8, 2021
@AndrewKushnir
Copy link
Contributor

Presubmit.

@AndrewKushnir
Copy link
Contributor

FYI presubmits went well for the changes in this PR.

@AndrewKushnir AndrewKushnir removed the action: presubmit The PR is in need of a google3 presubmit label May 8, 2021
@JoostK JoostK added the action: merge The PR is ready for merge by the caretaker label May 8, 2021
@alxhub alxhub closed this in a529d4f May 10, 2021
alxhub pushed a commit that referenced this pull request May 10, 2021
…42003)

The JIT compiler has a mapping from component to the owning NgModule
and tracks whether a certain NgModule class has been verified; these
maps causes any JIT compiled component and NgModule to be retained even
if they are no longer referenced from anywhere else. This commit
switches the maps to `WeakMap` to allow garbage collecting any
components and NgModules that are no longer referenced elsewhere.

Fixes #19997

PR Close #42003
alxhub pushed a commit that referenced this pull request May 10, 2021
…42003)

The JIT compiler has a mapping from component to the owning NgModule
and tracks whether a certain NgModule class has been verified; these
maps causes any JIT compiled component and NgModule to be retained even
if they are no longer referenced from anywhere else. This commit
switches the maps to `WeakMap` to allow garbage collecting any
components and NgModules that are no longer referenced elsewhere.

Fixes #19997

PR Close #42003
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jun 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime cla: yes memory leak Issue related to a memory leak target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compiler.compileModuleAsync related Issue - Memory Leak?
2 participants