我的网站上有一个带有画布的图表,它实时更改。每5秒ajax调用一个从数据库获取数据的函数,并将它们提供给另一个函数来制作画布。片刻之后,firefox ram的使用量达到300MB并且也会变大。什么问题和问题在哪里?我该如何解决这个问题?这是我的剧本:
function submitIpRequest(interval) {
if (!interval) {
switchIpdlCallChartInterval (false);
}
var formValues = $('#IpRequest').serialize();
//wait();
$.ajax({
type : 'POST',
url : baseUrl + 'monitoring/ipdl-call-chart',
data : formValues,
success : function(response) {
//waitStop();
var resultFull = $.parseJSON(response);
if (resultFull.msg) {
jqError( resultFull.msg, (resultFull.severity)?(resultFull.severity):('Error'));
return;
}
_disableIpdlCallFilterShowIcon ();
var result = resultFull.data;
if (0 == result.length) {
jqError( _("No data found for the given period of time"), "Warning");
return;
}
var timeInterval = $('#ipdlTimeInterval').val();
var markerValue = false;
switch (timeInterval){
case 'minute':
dateFormat = '%y-%#m-%#d %H:%M';
dateTickInterval = (Math.floor(resultFull.mDIA/10)+1) + ' minutes';
break;
case 'hour':
dateFormat = '%y-%#m-%#d %H:%M';
dateTickInterval = (Math.floor(resultFull.mDIA/10)+1) + ' hours';
console.log(dateTickInterval);
break;
case 'day':
dateFormat = '%y-%#m-%#d';
dateTickInterval = (Math.floor(resultFull.mDIA/10)+1) + ' days';
break;
case 'month':
dateFormat = '%y-%#m';
dateTickInterval = (Math.floor(resultFull.mDIA/10)+1) + ' months';
break;
case 'year':
dateFormat = '%y';
dateTickInterval = '1 year';
markerValue = true;
break;
}
xaxisOptions =
{
renderer: ( 'year' == timeInterval) ? ($.jqplot.CategoryAxisRenderer) : ($.jqplot.DateAxisRenderer),
labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
tickRenderer: $.jqplot.CanvasAxisTickRenderer,
tickOptions:{
formatString: ( 'year' == timeInterval) ? (null) : (dateFormat),
angle:-90,
},
min: ( resultFull.max == resultFull.min ) ? (null) : (resultFull.min),
max: ( resultFull.max == resultFull.min ) ? (null) : (resultFull.max),
tickInterval: ( 'year' == timeInterval) ? (null) : (dateTickInterval)
};
$('#ipRequestChart').html('');
ipdlCallChart = $.jqplot('ipRequestChart', [result], {
seriesDefaults: {
lineWidth:2,
showMarker:markerValue,
rendererOptions: {
padding: 10
}
},
height:"250px",
axes:{
xaxis:xaxisOptions,
yaxis:{
rendererOptions : {
tickRenderer : $.jqplot.CanvasAxisTickRenderer
},
numberTicks : 1,
tickOptions:{
formatString:'%i'
},
min: 0,
}
},
highlighter : {
show : true,
sizeAdjust : 2,
tooltipAxes : 'both',
useAxesFormatters : true,
}
});
},
error : function(XMLHttpRequest, textstatus, error) {
waitStop();
}
});
}
答案 0 :(得分:0)
感谢所有人。我解决了我不知道为什么但是当脚本通过超时调用自己时,似乎javascript的垃圾不起作用。我通过以下方式定义了我的变量:
my_variable = undefined;
在最后一次使用它之后。