From 811caafb53f199b77dc50d1752f5e4055686b0b3 Mon Sep 17 00:00:00 2001 From: Teemu Kokkonen Date: Tue, 22 Dec 2015 16:10:50 +0200 Subject: [PATCH] Fix angular.element.cache memory leak --- src/uiSelectChoicesDirective.js | 4 ++++ test/select.spec.js | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/src/uiSelectChoicesDirective.js b/src/uiSelectChoicesDirective.js index b1b79c874..c571f59c6 100644 --- a/src/uiSelectChoicesDirective.js +++ b/src/uiSelectChoicesDirective.js @@ -61,6 +61,10 @@ uis.directive('uiSelectChoices', $compile(element, transcludeFn)(scope); //Passing current transcludeFn to be able to append elements correctly from uisTranscludeAppend + scope.$on('$destroy', function() { + choices.remove(); + }); + scope.$watch('$select.search', function(newValue) { if(newValue && !$select.open && $select.multiple) $select.activate(false, true); $select.activeIndex = $select.tagging.isActivated ? -1 : 0; diff --git a/test/select.spec.js b/test/select.spec.js index 7c4018638..2a730d8f4 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -321,6 +321,13 @@ describe('ui-select tests', function() { }); + it('should not leak memory', function() { + var cacheLenght = Object.keys(angular.element.cache).length; + createUiSelect().remove(); + scope.$destroy(); + expect(Object.keys(angular.element.cache).length).toBe(cacheLenght); + }); + it('should compile child directives', function() { var el = createUiSelect();