dai

Jquery Ajax In Ie8 Memory Release

Recommended Posts

I use the Ajax object in IE8 myChart, memory has not been released, and in CHROME and FIREFOX did not appear in this situation.

 

The hope can help me to check. In addition, there are other solutions.

 

</span>
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>    
<head>   	
        <title></title>   	
        <meta http-equiv="pragma" content="no-cache">    	
	<meta http-equiv="cache-control" content="no-cache">    	
	<meta http-equiv="expires" content="0">    	
	<script src="../FusionChartsBroad/jquery-1.4.2.js"    type="text/javascript"></script>
		<script language="JavaScript"			src="../FusionChartsBroad/FusionCharts.js"></script>   
	</head>    
<body>    	
	<div id="chartdiv" align="center"></div>   
	</body>
</html>
<script type="text/javascript">    
	$(document).ready(function () {        
        setInterval("aa()",10000); 	
	});    
	function test() {      	
		$.ajax({          	
			type:"POST",       		
			url:"../FusionChartsBroad/Test_Error_Data.jsp", 	    		
			success: function(responseText){           
		         var myChart = new FusionCharts("../FusionChartsBroad/AngularGauge.swf", "myChartId", "350", "200", "0", "0");          	
				myChart.setDataXML(responseText);          	
				myChart.render("chartdiv");        	
				myChart = null;        	
				delete myChart;            
				CollectGarbage();        
         }       	
});   
     }
</script>

 

Edited by dai

Share this post


Link to post
Share on other sites

Hey,

 

In your ajax success function, what does CollectGarbage() do? In any case, a better approach would be if you rewrite the success function as (I am assuming that you are using the latest FusionCharts.js - 3.2.2-SR2):

 

function(responseText){
var myChart = window.myChart;

if (myChart) {
   myChart.dispose && myChart.dispose();
   delete window.myChart;
   myChart = null;
}

myChart = window.myChart = new FusionCharts("../FusionChartsBroad/AngularGauge.swf", "myChartId", "350", "200");                  
myChart.setXMLData(responseText);           	
myChart.render("chartdiv");
myChart = null;
}

 

In essence, before creating a new FusionCHarts instance, check to see if an older one exists. If yes then call dispose() on it. The code snippet of mine can be made more elegant, but essentially the logic remains this way.

 

Also, in case you are facing issues with memory release in JavaScript variants of the charts, then the upcoming release of FusionCharts (3.2.2.-SR3) should plug it up.

 

PS: I also spotted that you are using deprecated setDataXML()

Share this post


Link to post
Share on other sites

Hey,

 

In your ajax success function, what does CollectGarbage() do? In any case, a better approach would be if you rewrite the success function as (I am assuming that you are using the latest FusionCharts.js - 3.2.2-SR2):

 

function(responseText){
var myChart = window.myChart;

if (myChart) {
   myChart.dispose && myChart.dispose();
   delete window.myChart;
   myChart = null;
}

myChart = window.myChart = new FusionCharts("../FusionChartsBroad/AngularGauge.swf", "myChartId", "350", "200");                  
myChart.setXMLData(responseText);               
myChart.render("chartdiv");
myChart = null;
}

 

In essence, before creating a new FusionCHarts instance, check to see if an older one exists. If yes then call dispose() on it. The code snippet of mine can be made more elegant, but essentially the logic remains this way.

 

Also, in case you are facing issues with memory release in JavaScript variants of the charts, then the upcoming release of FusionCharts (3.2.2.-SR3) should plug it up.

 

PS: I also spotted that you are using deprecated setDataXML()

 

 

If the chart size isn't changing, wouldn't it be faster to see if the chart has already been rendered and simply call setXMLData on the original chart?

This is normally what we do - we have pages with 35 charts on them - I wouldn't want to take the time to dispose them all.

 

So:

 

if ( mychart) {
myChart.setXMLData(responseText);  
}
else{
myChart = window.myChart = new FusionCharts("../FusionChartsBroad/AngularGauge.swf", "myChartId", "350", "200");                  
myChart.setXMLData(responseText);               
myChart.render("chartdiv");
}

Share this post


Link to post
Share on other sites

If the chart size isn't changing, wouldn't it be faster to see if the chart has already been rendered and simply call setXMLData on the original chart?

This is normally what we do - we have pages with 35 charts on them - I wouldn't want to take the time to dispose them all.

...

 

 

Yeah, if the use-case does not "require" recreating the chart, simply setting new data will work.

 

PS: chart-type, chart-size and chart data can all be updated on a chart instance without creating a new FusionCharts every time.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now