fnClearTable + fnAddData Memory "Leak"

fnClearTable + fnAddData Memory "Leak"

JenMirJenMir Posts: 8Questions: 0Answers: 0
edited January 2011 in General
Hi,

I have an array that gets updated through Ajax every second. I can't use the built in Ajax function because I'm not transferring the whole array every time (only changes).

I saw some suggestions to use fnClearTable + fnAddData to refresh the data in the array. I got it working, but it uses more and more memory until the browser dies.

Am I doing something wrong or is this a bug? Or any suggestions on a different way to achieve a table refresh with the updated array?

I worked up an example from a modified js_array.html (from example files). It basically just calls a function every 100ms that does fnClearTable + fnAddData on an array and causes the exact issue I'm experiencing.

Edit: Seeing it in Firefox 3.6.13 and Chrome 8.0.552.237.Doesn't seem to affect IE8

Thanks in advance!

[code]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">





DataTables example

@import "../../media/css/demo_page.css";
@import "../../media/css/demo_table.css";




/* Data set - can contain whatever information you want */
var aDataSet = [
['Trident','Internet Explorer 4.0','Win 95+','4','X'],
['Trident','Internet Explorer 5.0','Win 95+','5','C'],
['Trident','Internet Explorer 5.5','Win 95+','5.5','A']
];

$(document).ready(function() {
$('#dynamic').html( '' );
exTable = $('#example').dataTable( {
"aaData": aDataSet,
"aoColumns": [
{ "sTitle": "Engine" },
{ "sTitle": "Browser" },
{ "sTitle": "Platform" },
{ "sTitle": "Version", "sClass": "center" },
{
"sTitle": "Grade",
"sClass": "center",
"fnRender": function(obj) {
var sReturn = obj.aData[ obj.iDataColumn ];
if ( sReturn == "A" ) {
sReturn = "A";
}
return sReturn;
}
}
]
} );
loadCounter();
function loadCounter(){
var $arr = [
['Trident','Internet Explorer 4.0','Win 95+','4','X'],
['Trident','Internet Explorer 5.0','Win 95+','5','C'],
['Trident','Internet Explorer 5.5','Win 95+','5.5','A'],
['Trident','Internet Explorer 6','Win 98+','6','A'],
['Trident','Internet Explorer 7','Win XP SP2+','7','A'],
['Trident','AOL browser (AOL desktop)','Win XP','6','A'],
['Gecko','Firefox 1.0','Win 98+ / OSX.2+','1.7','A'],
['Gecko','Firefox 1.5','Win 98+ / OSX.2+','1.8','A'],
['Gecko','Firefox 2.0','Win 98+ / OSX.2+','1.8','A'],
['Gecko','Firefox 3.0','Win 2k+ / OSX.3+','1.9','A'],
['Gecko','Camino 1.0','OSX.2+','1.8','A'],
['Gecko','Camino 1.5','OSX.3+','1.8','A'],
['Gecko','Netscape 7.2','Win 95+ / Mac OS 8.6-9.2','1.7','A'],
['Gecko','Netscape Browser 8','Win 98SE+','1.7','A'],
['Gecko','Netscape Navigator 9','Win 98+ / OSX.2+','1.8','A'],
['Gecko','Mozilla 1.0','Win 95+ / OSX.1+',1,'A'],
['Gecko','Mozilla 1.1','Win 95+ / OSX.1+',1.1,'A'],
['Gecko','Mozilla 1.2','Win 95+ / OSX.1+',1.2,'A'],
['Gecko','Mozilla 1.3','Win 95+ / OSX.1+',1.3,'A'],
['Gecko','Mozilla 1.4','Win 95+ / OSX.1+',1.4,'A'],
['Gecko','Mozilla 1.5','Win 95+ / OSX.1+',1.5,'A'],
['Gecko','Mozilla 1.6','Win 95+ / OSX.1+',1.6,'A'],
['Gecko','Mozilla 1.7','Win 98+ / OSX.1+',1.7,'A'],
['Gecko','Mozilla 1.8','Win 98+ / OSX.1+',1.8,'A'],
['Gecko','Seamonkey 1.1','Win 98+ / OSX.2+','1.8','A'],
['Gecko','Epiphany 2.20','Gnome','1.8','A'],
['Webkit','Safari 1.2','OSX.3','125.5','A'],
['Webkit','Safari 1.3','OSX.3','312.8','A'],
['Webkit','Safari 2.0','OSX.4+','419.3','A']
];
exTable.fnClearTable();
exTable.fnAddData($arr);
setTimeout(loadCounter, 100);
}


} );




Live example




[/code]

Replies

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Hi JenMir,

    Thanks very much for the script - I'll give it a go in a little while when I get a chance. I suspect there might well be a leak somewhere - I'm just not sure where at the moment I'm afraid...

    Allan
  • JenMirJenMir Posts: 8Questions: 0Answers: 0
    Thank you! Very much appreciated!
This discussion has been closed.