我正在使用这个简单的html文件来重现我发现的内存泄漏:
<!doctype html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular.min.js"></script>
<script>
var app = angular.module('testApp', []);
app.directive('directive1', function() {
return {
template: '<div directive2></div>',
scope: true
};
});
app.directive('directive2', function () {
function LeakObject() {}
function Foo() {
this.bar = function($scope) {
$scope.nottheredude;
};
}
return {
scope: true,
link: function($scope) {
$scope.memoryThatLeaks = new LeakObject();
new Foo().bar({});
new Foo().bar($scope);
}
};
});
</script>
</head>
<body ng-app="testApp">
<button ng-click="show = !show">Toggle</button>
<div ng-if="show">The directive <div directive1></div></div>
<div ng-if="!show">Nothing</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我有一个指令,只创建一个新的范围,并在其模板中有另一个指令.
另一个指令做了一些有点奇怪的事情(我试图将问题缩小到导致泄漏的问题,这是我发现的最短代码再现问题).
在我的主要HTML中,我只是在没有任何东西和 …