@@ -4537,6 +4537,58 @@ describe('$compile', function() {
4537
4537
} ) ;
4538
4538
} ) ;
4539
4539
4540
+ it ( 'should not leak when continuing the compilation of elements on a scope that was destroyed' , function ( ) {
4541
+ if ( jQuery ) {
4542
+ // jQuery 2.x doesn't expose the cache storage.
4543
+ return ;
4544
+ }
4545
+
4546
+ var linkFn = jasmine . createSpy ( 'linkFn' ) ;
4547
+
4548
+ module ( function ( $controllerProvider , $compileProvider ) {
4549
+ $controllerProvider . register ( 'Leak' , function ( $scope , $timeout ) {
4550
+ $scope . code = 'red' ;
4551
+ $timeout ( function ( ) {
4552
+ $scope . code = 'blue' ;
4553
+ } ) ;
4554
+ } ) ;
4555
+ $compileProvider . directive ( 'red' , function ( ) {
4556
+ return {
4557
+ restrict : 'A' ,
4558
+ templateUrl : 'red.html' ,
4559
+ scope : { } ,
4560
+ link : linkFn
4561
+ } ;
4562
+ } ) ;
4563
+ } ) ;
4564
+
4565
+ inject ( function ( $compile , $rootScope , $httpBackend , $timeout , $templateCache ) {
4566
+ $httpBackend . whenGET ( 'red.html' ) . respond ( '<p>red.html</p>' ) ;
4567
+ var template = $compile (
4568
+ '<div ng-controller="Leak">' +
4569
+ '<div ng-switch="code">' +
4570
+ '<div ng-switch-when="red">' +
4571
+ '<div red></div>' +
4572
+ '</div>' +
4573
+ '</div>' +
4574
+ '</div>' ) ;
4575
+ element = template ( $rootScope ) ;
4576
+ $rootScope . $digest ( ) ;
4577
+ $timeout . flush ( ) ;
4578
+ $httpBackend . flush ( ) ;
4579
+ expect ( linkFn ) . not . toHaveBeenCalled ( ) ;
4580
+ expect ( jqLiteCacheSize ( ) ) . toEqual ( 2 ) ;
4581
+
4582
+ $templateCache . removeAll ( ) ;
4583
+ var destroyedScope = $rootScope . $new ( ) ;
4584
+ destroyedScope . $destroy ( ) ;
4585
+ var clone = template ( destroyedScope ) ;
4586
+ $rootScope . $digest ( ) ;
4587
+ $timeout . flush ( ) ;
4588
+ expect ( linkFn ) . not . toHaveBeenCalled ( ) ;
4589
+ } ) ;
4590
+ } ) ;
4591
+
4540
4592
if ( jQuery ) {
4541
4593
describe ( 'cleaning up after a replaced element' , function ( ) {
4542
4594
var $compile , xs ;
0 commit comments