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

Commit 811caaf

Browse files
author
Teemu Kokkonen
committed
Fix angular.element.cache memory leak
1 parent 3b1496c commit 811caaf

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/uiSelectChoicesDirective.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ uis.directive('uiSelectChoices',
6161

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

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

test/select.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,13 @@ describe('ui-select tests', function() {
321321

322322
});
323323

324+
it('should not leak memory', function() {
325+
var cacheLenght = Object.keys(angular.element.cache).length;
326+
createUiSelect().remove();
327+
scope.$destroy();
328+
expect(Object.keys(angular.element.cache).length).toBe(cacheLenght);
329+
});
330+
324331
it('should compile child directives', function() {
325332
var el = createUiSelect();
326333

0 commit comments

Comments
 (0)