Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 90dc38e

Browse files
committed
fix(element binder): fix memory leak with expando value holding onto node
Expando keys are weak references but the values are not. The ElementProbe value holds strong references to the node and the injector keep it from being garbage collected.
1 parent 00022bd commit 90dc38e

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

test/core_dom/compiler_spec.dart

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,28 @@ void main() {
727727
expect(_.rootElement.shadowRoot).toBeNotNull();
728728
}
729729
}));
730+
731+
describe('expando memory', () {
732+
Expando expando;
733+
734+
beforeEach(inject((Expando _expando) => expando = _expando));
735+
736+
['shadowy', 'shadowless'].forEach((selector) {
737+
it('should release expando when a node is freed ($selector)', async(() {
738+
_.rootScope.context['flag'] = true;
739+
_.compile('<div><div ng-if=flag><$selector>x</$selector></div></div>');
740+
microLeap(); _.rootScope.apply();
741+
var element = _.rootElement.querySelector('$selector');
742+
if (element.shadowRoot != null) {
743+
element = element.shadowRoot;
744+
}
745+
expect(expando[element]).not.toEqual(null);
746+
_.rootScope.context['flag'] = false;
747+
microLeap(); _.rootScope.apply();
748+
expect(expando[element]).toEqual(null);
749+
}));
750+
});
751+
});
730752
});
731753

732754
describe('bindings', () {
@@ -849,7 +871,6 @@ void main() {
849871
expect(_.rootElement.text).toEqual('MyController');
850872
});
851873
});
852-
853874
}));
854875
}
855876

@@ -975,6 +996,16 @@ class SimpleComponent {
975996
}
976997
}
977998

999+
@Component(
1000+
selector: 'simple2',
1001+
template: r'{{name}}(<content>SHADOW-CONTENT</content>)')
1002+
class Simple2Component {
1003+
Scope scope;
1004+
Simple2Component(Scope this.scope) {
1005+
scope.context['name'] = 'INNER';
1006+
}
1007+
}
1008+
9781009
@Component(
9791010
selector: 'shadowy',
9801011
template: r'With shadow DOM',

0 commit comments

Comments
 (0)