-
Notifications
You must be signed in to change notification settings - Fork 27.5k
ngRepeat "track by" possible memory leak #16776
Comments
Thx for reporting this. Have you manually triggered GC before taking the heap snapshot? If the element is not reachable (as you said), then it would be a GC bug not to get rid of it. |
@gkalpak Taking a heap snapshot automatically runs GC beforehand. |
I updated the Plunker and repro steps to make it a bit clearer. |
I might not be reading this right but as far as I can tell only one instance is ever created, even if you toggle the ng-if many times. I appreciate that this doesn't mean there is no memory leak but it does give us some more information for debugging this... |
@petebacondarwin True, the scope of the leak is limited. But if the controller were to have enough data in it and/or have $scope injected (which could lead to the whole scope tree leaking), the impact could be noticeable on memory usage. |
Good catch @bensgroi! Turns out there's actually 2 problems:
|
This also fixes a leak of that scope across all further instances of the repeated element. Fixes angular#16776
This also fixes a leak of that scope across all further instances of the repeated element. Fixes angular#16776
This also fixes a leak of that scope across all further instances of the repeated element. Fixes angular#16776 Closes angular#16777
Also fixes a leak of that scope across all further instances of the repeated element. Fixes angular#16776 Closes angular#16777
Also fixes a leak of that scope across all further instances of the repeated element. Fixes angular#16776 Closes angular#16777
For reference, another issue we found which will also be fixed:
|
I'm submitting a ...
Current behavior:
Adding a
track by
to anngRepeat
causes a memory leak, so that the component's controller is retained in memory.Expected / new behavior:
Using
track by
on anngRepeat
should not cause any side effects.Minimal reproduction of the problem with instructions:
Plunker
To see the memory leak in action, you'll need to run the demo in its own tab: https://run.plnkr.co/plunks/pToAURpUzO2pdOq6H0Yf/
It contains two child components, a "leaky" version and a "non-leaky" version, the only difference between them being the addition of a "track by" on the leaky one.
The presence of "track by" seems to cause a leak. Using
track by $index
has the same effect. This seems like a really obvious bug, but I haven't been able to find anything related to it here yet. Am I missing something?AngularJS version: 1.7.5
Also reproduced in 1.5.8
Browser: Chrome 70
The text was updated successfully, but these errors were encountered: