问题
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