Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit 3a4d5b4

Browse files
committed
Merge pull request #1365 from fastmonkeys/fix-angular-element-cache-memory-leak
perf(uiSelect) fix angular.element.cache memory leak
2 parents 04eb3f6 + 811caaf commit 3a4d5b4

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/uiSelectChoicesDirective.js

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ uis.directive('uiSelectChoices',
5959

6060
$compile(element, transcludeFn)(scope); //Passing current transcludeFn to be able to append elements correctly from uisTranscludeAppend
6161

62+
scope.$on('$destroy', function() {
63+
choices.remove();
64+
});
65+
6266
scope.$watch('$select.search', function(newValue) {
6367
if(newValue && !$select.open && $select.multiple) $select.activate(false, true);
6468
$select.activeIndex = $select.tagging.isActivated ? -1 : 0;

test/select.spec.js

+7
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,13 @@ describe('ui-select tests', function() {
348348

349349
});
350350

351+
it('should not leak memory', function() {
352+
var cacheLenght = Object.keys(angular.element.cache).length;
353+
createUiSelect().remove();
354+
scope.$destroy();
355+
expect(Object.keys(angular.element.cache).length).toBe(cacheLenght);
356+
});
357+
351358
it('should compile child directives', function() {
352359
var el = createUiSelect();
353360

0 commit comments

Comments
 (0)