iFrame Memory Leak in Angular JS and Chrome (noticed in 63 but dates back until at least 58)

让人想犯罪 __ 提交于 2020-01-04 05:27:05

问题


Very simple single page angular application, using an iframe in one of the views / routes, creates a memory leak / constantly increments the document count. This did not happen in the past.

It seems to happen on any angular js version using the latest Chrome browsers.

Check this plunker: https://plnkr.co/edit/oO6PzzN1YEKTwsOcjRAd:

HTML:

<html ng-app="project">
  <head>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.14/angular.js"></script>
        <script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.4.14/angular-route.js'></script>
    <script src="script.js"></script>
  </head>
  <body>
        <div ng-view></div>
  </body>
</html>

Script.js

angular.module('project', ['ngRoute']).
        config(function ($routeProvider,$locationProvider) {
            // in case we want to test with Angular 1.6
            $locationProvider.hashPrefix('');
            //$sce.trustAsResourceUrl("//www.youtube.com/embed/dQw4w9WgXcQ");
            $routeProvider.
                    when('/', {controller: MyCtrl, templateUrl: 'include.html'});
            $routeProvider.
                    when('/home', {controller: MyCtrl, templateUrl: 'include.html'});
            $routeProvider.
                    when('/frame', {controller: FrameCtrl, templateUrl: 'frame.html'});

        });


function MyCtrl($scope) {

}

function FrameCtrl($scope,$sce) {

     $scope.currentProjectUrl = $sce.trustAsResourceUrl("//www.youtube.com/embed/dQw4w9WgXcQ");
}

include.html:

Page A...click forward and watch the browser never release the documents in the iframe
<a href='#frame'>Forward</a>

frame.html:

<div>
    Page causing the memory leak - click back.  Rinse, repeat and check the memory profile
    <a href='#/home'>Back</a>
    <iframe src="{{currentProjectUrl}}">
    </iframe>    
</div>

If you open developer tabs, select Performance, and check Documents, and repeatedly switch between the views you will notice the document count never decreases!

Any idea how to force the memory to release or are iframes, angular js and chrome now broken?

来源:https://stackoverflow.com/questions/47929043/iframe-memory-leak-in-angular-js-and-chrome-noticed-in-63-but-dates-back-until

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!