@@ -4470,6 +4470,58 @@ describe('$compile', function() {
4470
4470
} ) ;
4471
4471
} ) ;
4472
4472
4473
+ it ( 'should not leak when continuing the compilation of elements on a scope that was destroyed' , function ( ) {
4474
+ if ( jQuery ) {
4475
+ // jQuery 2.x doesn't expose the cache storage.
4476
+ return ;
4477
+ }
4478
+
4479
+ var linkFn = jasmine . createSpy ( 'linkFn' ) ;
4480
+
4481
+ module ( function ( $controllerProvider , $compileProvider ) {
4482
+ $controllerProvider . register ( 'Leak' , function ( $scope , $timeout ) {
4483
+ $scope . code = 'red' ;
4484
+ $timeout ( function ( ) {
4485
+ $scope . code = 'blue' ;
4486
+ } ) ;
4487
+ } ) ;
4488
+ $compileProvider . directive ( 'red' , function ( ) {
4489
+ return {
4490
+ restrict : 'A' ,
4491
+ templateUrl : 'red.html' ,
4492
+ scope : { } ,
4493
+ link : linkFn
4494
+ } ;
4495
+ } ) ;
4496
+ } ) ;
4497
+
4498
+ inject ( function ( $compile , $rootScope , $httpBackend , $timeout , $templateCache ) {
4499
+ $httpBackend . whenGET ( 'red.html' ) . respond ( '<p>red.html</p>' ) ;
4500
+ var template = $compile (
4501
+ '<div ng-controller="Leak">' +
4502
+ '<div ng-switch="code">' +
4503
+ '<div ng-switch-when="red">' +
4504
+ '<div red></div>' +
4505
+ '</div>' +
4506
+ '</div>' +
4507
+ '</div>' ) ;
4508
+ element = template ( $rootScope ) ;
4509
+ $rootScope . $digest ( ) ;
4510
+ $timeout . flush ( ) ;
4511
+ $httpBackend . flush ( ) ;
4512
+ expect ( linkFn ) . not . toHaveBeenCalled ( ) ;
4513
+ expect ( jqLiteCacheSize ( ) ) . toEqual ( 2 ) ;
4514
+
4515
+ $templateCache . removeAll ( ) ;
4516
+ var destroyedScope = $rootScope . $new ( ) ;
4517
+ destroyedScope . $destroy ( ) ;
4518
+ var clone = template ( destroyedScope ) ;
4519
+ $rootScope . $digest ( ) ;
4520
+ $timeout . flush ( ) ;
4521
+ expect ( linkFn ) . not . toHaveBeenCalled ( ) ;
4522
+ } ) ;
4523
+ } ) ;
4524
+
4473
4525
if ( jQuery ) {
4474
4526
describe ( 'cleaning up after a replaced element' , function ( ) {
4475
4527
var $compile , xs ;
0 commit comments