Sitelet https://github.com/angular/angular/issues/20007
Skip to content

Memory leak when FormControlName created/destroyed few times #20007

Description

@IliaVolk

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

  1. FormControlName, objects provided by NG_VALIDATORS (may be some other) can not be collected by gc until there are refs for FormGroup.
    This is caused by collecting closures created in https://github.com/angular/angular/blob/4.4.6/packages/forms/src/directives/shared.ts#L33 in https://github.com/angular/angular/blob/4.4.6/packages/forms/src/model.ts#L744 .
  2. All provided validators (via NG_VALIDATORS token) are called as many times as form is recreated.

Expected behavior

  1. After destroying FormControlName it should be collected by gc even if there are refs for FormGroup.
  2. Provided validators should be removed from FormControl after destroying FormControlName.

Minimal reproduction of the problem with instructions

https://plnkr.co/edit/eCtf2naoxLe8bWTJ8IkV?p=preview (used example from material demo as starting point)

Steps to reproduce

  1. show/hide form clicking checkbox.
  2. displayed below number of listeners is increasing.
  3. there are more and more messages 'Validate called' appears in console when editing input (In my project I had issue when validators set outdated errors, had to use workaround).

There are 3 inputs to show that they are not synchronized (Is there a significant reason to store all closures, not only last?).

What is the motivation/use case for changing the behavior?

  1. Allow to have permanent FormControl/FormGroup without memory leaks.
  2. Allow to dynamically create FormControlName with custom control, which knows how to validate itself (providing NG_VALIDATORS), without calling validators of destroyed controls.

Environment


Angular version: 4.4.6


Browser:
- [x] Chrome (desktop) version 62.0.3202.75
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
Others:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions