dart-archive / angular.dart

Legacy source repository. See github.com/dart-lang/angular
https://webdev.dartlang.org/angular/
1.25k stars 248 forks source link

NgRepeat with bound variable memory leak #1680

Open mckgamer opened 9 years ago

mckgamer commented 9 years ago

Small repro example: This component merely contains a list of Strings and defines a method remove, which will remove the given string from the list.

@Component( selector: 'parent-component', templateUrl: 'parent_component.html') class ParentComponent {

List theList = new List();

ParentComponent() { theList.add('a'); theList.add('b'); theList.add('c'); theList.add('d'); theList.add('e'); theList.add('f'); theList.add('g'); }

void remove(String rem) { theList.remove(rem); } }

Its HTML is an ng-repeat of the component "RepeatedComponent" over the list of strings. When any of these is clicked, the rmeove method is called to remove its string from the list.

<repeated-component ng-repeat = "name in theList" name = "name" ng-click = "remove(name)">

Repeated component does nothing but store the bound variable "name".

@Component( selector: 'repeated-component', templateUrl: 'repeated_component.html' ) class RepeatedComponent {

@NgOneWay('name') String name;

}

Its HTML just displays "name" in a div.

{{name}}

Within Chromium, in Observatory -> Class Hierarchy and find "RepeatedComponent". It should show Currently allocated 7 and all 7 are strongly reachable, which is expected. Upon clicking on one of the displayed "RepeatedComponent"s to remove it, it is removed from the list as expected, but upon refreshing the Observatory tab, both the currently allocated and strongly reachable counts stay at 7.

Now, if we do the same exact thing but remove the @NgOneWay binding of name inside "RepeatedComponent", the number of currently allocated stays the same but strongly reachable goes down to 6 as it should.

Our conclusion is becoming that there is some sort of bug between the interaction of ng-repeat and the bound variable.

mckgamer commented 9 years ago

Any insight?