[英]Memory leak in setInterval() method
I am creating a javascript based html dashboard. 我正在创建一个基于javascript的html仪表板。 In order to refresh the values in the dashboard charts I have written the following code: 为了刷新仪表板图表中的值,我编写了以下代码:
var chart, options;
function loadDynamicData() {
var data = window.parent.getDynamicData();
var dataArray = data.split(',');
for(var i = 0; i < chartData.length; i++) {
chartData[i].data.pop();
chartData[i].data.push(parseInt(dataArray[i],10));
}
}
$(document).ready(function() {
//initialize options here
setInterval(function () {
loadDynamicValues(); // loads dynamic values through ajax
// and updates options
chart = new Highcharts.Chart(options);
}, 300000);
});
But the problem is when I run this in the browser for a long time (about 1 hour), the memory being used goes up and the browser becomes unresponsive. 但问题是当我在浏览器中运行这个很长一段时间(大约1小时)时,正在使用的内存会上升,浏览器就会无法响应。 If I remove the setInterval()
method and run the code that is inside for once, then there is no problem. 如果我删除setInterval()
方法并运行一次内部代码,那么没有问题。
What can be the problem here? 这可能是什么问题?
Please do a chart.destroy() before creating new chart. 请在创建新图表之前执行chart.destroy()。
if (chart) chart.destroy; if(chart)chart.destroy;
Here is a link for test. 这是一个测试链接。 http://www.highcharts.com/tests/?file=memory-chart-destroy http://www.highcharts.com/tests/?file=memory-chart-destroy
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.