Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

nested transclusion memory leak #7913

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3927,6 +3927,33 @@ describe('$compile', function() {
});
});

it('should not leak memory with nested transclusion', function() {
var calcCacheSize = function() {
var size = 0;
forEach(jqLite.cache, function(item, key) { size++; });
return size;
};

inject(function($compile, $rootScope) {
var size;

expect(calcCacheSize()).toEqual(0);

element = jqLite('<div><ul><li ng-repeat="n in nums">{{n}} => <i ng-if="0 === n%2">Even</i><i ng-if="1 === n%2">Odd</i></li></ul></div>');
$compile(element)($rootScope.$new());

$rootScope.nums = [0,1,2];
$rootScope.$apply();
size = calcCacheSize();

$rootScope.nums = [3,4,5];
$rootScope.$apply();
expect(calcCacheSize()).toEqual(size);

element.remove();
expect(calcCacheSize()).toEqual(0);
});
});

it('should remove transclusion scope, when the DOM is destroyed', function() {
module(function() {
Expand All @@ -3950,7 +3977,7 @@ describe('$compile', function() {
$rootScope.username = 'Misko';
$rootScope.select = true;
element = $compile(
'<div><div box name="username" show="select">user: {{username}}</div></div>')
'<div ng-if="1<2"><div box name="username" show="select">user: {{username}}</div></div>')
($rootScope);
$rootScope.$apply();
expect(element.text()).toEqual('Hello: Misko!user: Misko');
Expand Down