Javascript AngularJS页面导致Chrome在后台使用巨大的选项卡内存
我有一个非常简单的AngularJS页面,它只是使用一个服务从后端提取数据,并使用ng repeat在屏幕上显示数据 在10分钟后的正常使用期间,页面的内存稳定在100mb左右。如果我切换选项卡,使该页面不再聚焦-它在后台,它将在内存中膨胀到1gb,然后崩溃 我正在使用Javascript AngularJS页面导致Chrome在后台使用巨大的选项卡内存,javascript,angularjs,google-chrome,momentjs,Javascript,Angularjs,Google Chrome,Momentjs,我有一个非常简单的AngularJS页面,它只是使用一个服务从后端提取数据,并使用ng repeat在屏幕上显示数据 在10分钟后的正常使用期间,页面的内存稳定在100mb左右。如果我切换选项卡,使该页面不再聚焦-它在后台,它将在内存中膨胀到1gb,然后崩溃 我正在使用$interval刷新数据,最近我读到,当页面位于后台时,Chrome会限制间隔和超时。这难道不应该阻止这种情况发生吗?我能做什么?作为最后一种手段,我已经考虑切换到requestAnimationFrame,因为我知道当页面位于
$interval
刷新数据,最近我读到,当页面位于后台时,Chrome会限制间隔和超时。这难道不应该阻止这种情况发生吗?我能做什么?作为最后一种手段,我已经考虑切换到requestAnimationFrame
,因为我知道当页面位于后台时不会调用它
$interval($scope.update, $scope.refreshInterval);
//
//
//
$scope.update = function () {
$scope.inError = false;
scheduleAppAPIservice.getSchedules().then(
function (response) {
$scope.schedules = null;
$scope.schedules = response.data;
angular.forEach($scope.schedules, $scope.createNextExecutionLabel);
angular.forEach($scope.schedules, $scope.createTrclass);
angular.forEach($scope.tabs, $scope.assignSchedulesToTab);
$scope.loading = false;
},
function () {
$scope.inError = true;
//console.log("failed getSchedules");
});
};
//
//
//
$scope.createNextExecutionLabel = function (schedule) {
schedule.nextExecutionDate = moment(schedule.NextExecution);
schedule.endExecutionDate = moment(schedule.EndExecution);
if (schedule.nextExecutionDate.year() > $scope.finishedCutoffYear) {
schedule.nextExecutionLabel = "Never";
}
else if (schedule.IsCurrentlyExecuting) {
schedule.nextExecutionLabel = "Running";
if (!isNaN(schedule.CurrentProgress) && schedule.CurrentProgress != 0) {
schedule.nextExecutionLabel += " (" + schedule.CurrentProgress + "%)";
}
else {
schedule.nextExecutionLabel += "...";
}
}
else if (schedule.nextExecutionDate < moment()) {
schedule.nextExecutionLabel = "Overdue";
}
else {
schedule.nextExecutionLabel = $filter('emRelativeTime')(schedule.nextExecutionDate);
}
}
//
//
//
$scope.createTrclass = function (schedule) {
var trclass = "system";
if (schedule.IsDisabled) {
trclass = "disabled";
}
else if (schedule.IsUserSchedule) {
if (schedule.nextExecutionDate.year() > $scope.finishedCutoffYear && schedule.ExecuteOnEvent == 0)
trclass = "finished";
else
trclass = "active";
}
schedule.trclass = trclass;
};
//
//
//
$scope.assignSchedulesToTab = function (tab) {
tab.scheduleCount = $scope.schedules.filter(function (x) {
return x.trclass == tab.label.toLowerCase();
}).length;
};
$interval($scope.update,$scope.refreshInterval);
//
//
//
$scope.update=函数(){
$scope.inError=false;
scheduleAppAPIservice.getSchedules()。然后(
功能(响应){
$scope.schedules=null;
$scope.schedules=response.data;
angular.forEach($scope.schedules,$scope.createNextExecutionLabel);
forEach($scope.schedules,$scope.createtClass);
forEach($scope.tabs,$scope.assignSchedulesToTab);
$scope.loading=false;
},
函数(){
$scope.inError=true;
//log(“失败的getSchedules”);
});
};
//
//
//
$scope.createNextExecutionLabel=函数(计划){
schedule.NextExecution日期=时刻(schedule.NextExecution);
schedule.endExecutionDate=时刻(schedule.EndExecution);
if(schedule.nextExecutionDate.year()>$scope.finishedCutoffYear){
schedule.nextExecutionLabel=“从不”;
}
else if(schedule.iscurrently正在执行){
schedule.nextExecutionLabel=“正在运行”;
如果(!isNaN(schedule.CurrentProgress)&&schedule.CurrentProgress!=0){
schedule.nextExecutionLabel+=”(“+schedule.CurrentProgress+”)”;
}
否则{
schedule.nextExecutionLabel+=“…”;
}
}
else if(schedule.nextExecutionDate<矩()){
schedule.nextExecutionLabel=“过期”;
}
否则{
schedule.nextExecutionLabel=$filter('emRelativeTime')(schedule.nextExecutionDate);
}
}
//
//
//
$scope.createTrclass=函数(计划){
var trclass=“系统”;
如果(附表IsDisabled){
trclass=“已禁用”;
}
else if(schedule.IsUserSchedule){
if(schedule.nextExecutionDate.year()>$scope.finishedCutoffYear&&schedule.ExecuteOnEvent==0)
trclass=“完成”;
其他的
trclass=“活动”;
}
schedule.trclass=trclass;
};
//
//
//
$scope.assignSchedulesToTab=函数(选项卡){
tab.scheduleCount=$scope.schedules.filter(函数(x){
返回x.trclass==tab.label.toLowerCase();
}).长度;
};
我没有任何关于后台选项卡节流的信息,因此,这个答案中的理论可能不正确
$interval
每5秒工作一次。
但是,$interval
内的成功承诺可能无法在5秒内解决
因此,如果由于某种原因,scheduleAppAPIservice.getSchedules()
无法在5秒内解析,那么在每个$interval
周期中,承诺的数量增加将消耗内存
在
$interval
上启动一个新请求时,您可以取消上一个请求,或者在promise完成时,您可以使用$timeout
+手动调用下一个请求,以确保没有任何内容以不受控制的方式消耗内存。该问题的解决方案?我也经历过