Memory problems

Memory problems

bulebule Posts: 8Questions: 0Answers: 0
edited April 2009 in General
Hi all,
first of all thanks a lot for this great and complete plugin...

I write here because I have a memory problem with the data table, I'll try to explain my problem:

on document.ready I write the content of table, adding rows with:
--> $('table tbody').append(row);
when all rows are added I call the datatable plugin:
--> global_table = $('table').dataTable({"some options here"});

and till now any problems , all work great.

Then I have to change the content of the table so I call
-->global_table.fnClearTable( global_table );
then I rewrite the table
--> $('table tbody').append(newrow);

I recall the plugin :
--> global_table = $('table').dataTable({"some options here"});

after this all works fine but browser memory grows up
it seems that the variable inside the plugin would not empty...

hope someone can help me or suggest a better way to make the table refresh ..
Best Regards


  • allanallan Posts: 54,880Questions: 1Answers: 8,601 Site admin
    Hi bule,

    Interesting one - and potentially slightly worrying is DataTables has a leak in it. I'll need to dig into this a bit more as time allows, but just to check, you aren't apply event handlers to your DOM node are? That would also certainly create a leak if they aren't removed.

  • bulebule Posts: 8Questions: 0Answers: 0
    allan, the call to the datatable is the following:

    "aoColumns": [{ "bSortable": false,"bSearchable": false },{"sType": "html" }],
    "oLanguage": {"sUrl": "javascript/dataTables-1.4/media/language/it_IT.txt"},
    "aaSorting": [[ 1, "asc" ]]

    so i don't use event for the table,

    but after the creation I bind some event in this way :

    $('table tbody tr').unbibd(); <--think this remove past events
    $('table tbody tr').click( function(){dosomething...});

    are you thinking about this when you speak about event handlers applayed to dom ?
  • allanallan Posts: 54,880Questions: 1Answers: 8,601 Site admin
    Hi bule,

    Yes it's the events you bind to the table rows which I was thinking about. The thing with this is that the event listener will retain a pointer to the node that it is attached to, and therefore the garbage collector won't be able to drop the memory allocated for that node.

    What I think you could do to solve this (assuming that I am correct in my assumptions...) is to call "$('table tbody tr').unbibd()" just before you call fnClearTable(). Then the nodes will have no references to them, and should be cleaned up.

    Also worth noting, you might want to take a look at this example for adding event handlers to table rows when you have paging enabled: . I think at the moment you might be applying the events to only the rows which are visible on the current page. Likewise the unbind.

    If you could let me know how this goes, that would be great.

  • bulebule Posts: 8Questions: 0Answers: 0
    allan, i have try to call the unbind just before the table cleaning up but lucky day for me :-)
    memory still increases..

    Tomorrow I'll make other trys and then I hope I can tell to you something more useful...
This discussion has been closed.