udos86 / ng-dynamic-forms

Rapid form development library for Angular
ISC License
1.32k stars 369 forks source link

Recreation of form produces memory leak #985

Open romejoseph opened 5 years ago

romejoseph commented 5 years ago

I'm submitting a


[x] Bug / Regression
[ ] Feature Request / Proposal

I'm using


NG Dynamic Forms Version: `6.2.0`

[ ] Basic UI
[ ] Bootstrap UI  
[ ] Foundation UI
[ ] Ionic UI
[ ] Kendo UI
[ ] Material  
[ ] NG Bootstrap
[x] Prime NG

Description

We're having a problem about memory leak when a form is recreated over time. I've found an unresolved issue in angular that may be related to this bug.

This is a stackblitz to reproduce the bug. Just open and close the form and see the memory increase for every step. The bigger the form is, the larger the memory leak.

udos86 commented 5 years ago

@romejoseph Thank you very much for reporting this.

If this is directly related to the Angular Issue there's not much I could do but I'll take a closer look.

udos86 commented 5 years ago

@romejoseph

Just to gain some deeper insight into your use case:

Karamuto commented 5 years ago

Hello @romejoseph ,

I agree with udo here, as this is actually an angular bug, which we can't resolve ourself. But as you look into the issue, you can find some workaround to this issue, like 'hide' the controls instead of making an ngIf.

romejoseph commented 5 years ago

@udos86

We have forms that get updated dynamically from the back-end based on data entered by the user. When something is changed by the user, we execute a REST API call to the back-end, which returns updates. For example, if the user selects a certain value in a drop-down (e.g. selects country), the options in the next drop-down change (e.g. list of states), or another example is a calculated field based on values entered in other fields. There can also be warnings returned by the back-end which will be displayed next to the relevant field.

So we need to recreate the form when a relevant field changes (there can be many on a form). To avoid flickering of the form, we update the model, but not the form group.

Our forms can have 50-100 fields, typically a quarter of them would trigger an update/recreate (ballpark figures).

kovax commented 5 years ago

@udos86 and @Karamuto

I think opening and closing forms (i.e. recreating) is not special to our application (I work with @romejoseph), any SPA can have a button or menu item that a user can click on many times. On the other hand we have very big forms. which I agree not the best design, but our client want them this way. On the bright side it helped us to reproduce this bug ...

I would really appreciate if you could confirm that this is an Angular bug, and if so, help us to convince them to fix it.