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
- 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 .
- All provided validators (via NG_VALIDATORS token) are called as many times as form is recreated.
Expected behavior
- After destroying FormControlName it should be collected by gc even if there are refs for FormGroup.
- 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
- show/hide form clicking checkbox.
- displayed below number of listeners is increasing.
- 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?
- Allow to have permanent FormControl/FormGroup without memory leaks.
- 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:
I'm submitting a...
Current behavior
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 .
Expected behavior
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
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?
Environment