Datatables+TableTools memory leak?

Datatables+TableTools memory leak?

jeroenvandoorenjeroenvandooren Posts: 2Questions: 0Answers: 0
edited December 2013 in General
Hi all,

we're using a single page website with datatables 1.9.4 and tabletools 2.1.4 and are having issues with memory leaks.
This is a website that is used by our customers, I'm not allowed to grant you access to it. The complexity of the code is such that it isn't easily isolatable into an example (datatables + ajax).

In this single page website, we re-create the complete page content containing a datatable upon every refresh or update.
A refresh or update is triggered by a treeview with nodes, where every node click shows its own datatables grid (indirectly replacing the previously shown datatables grid).
Our gridsizes are between 2500 and 3500 rows, making a leak very visible.

I dived into the memory leaks using IE11 memory profiler/snapshots and found that numerous event handlers kept lingering around in the jquery.cache, holding parts or the whole of the datatable.
I also learned that calling fnDestroy doesn't work when the datatables node is already removed from the DOM. Calling it before the async postback of the page update when the previous table still is in the DOM also doesn't clear everything.

I was very surprised to see that also the example on the datatables site: http://datatables.net/release-datatables/examples/api/select_single_row.html
also appears to leak memory when looking at the IE11 memory profiler. This leak is very small since there are only 57 rows.
Using the IE11 memory snapshot, I think I see similar event handlers lingering around in the jquery.cache that aren't connected to the DOM anymore.

Am I correct in my assumption on the leak in the example and is there an explanation as to why this happens? The answer might help us in figuring out how to use datatables on a single page website...

Ps. The DataTables debugger is stuck on "uploading data to the server" for over 30 minutes, if I get a sensible response, I'll post it.

Replies

  • jeroenvandoorenjeroenvandooren Posts: 2Questions: 0Answers: 0
    Debug code: acivam
  • brailateobrailateo Posts: 7Questions: 0Answers: 0
    I've got the same memory leak with Google Chrome DevTools!
    First question: do you have invisible ("bVisible":false) columns in your dataTable?
    If yes, please try to remove them and check again if the memory leak is present!
    Also, try to replace in the jQuery.datatables.js the fnDestroy function with this version and see if better!
    [code]
    this.fnDestroy = function ( bRemove )
    {
    var oSettings = _fnSettingsFromNode( this[DataTable.ext.iApiIndex] );
    var nOrig = oSettings.nTableWrapper.parentNode;
    var nBody = oSettings.nTBody;
    var i, iLen;

    bRemove = (bRemove===undefined) ? false : bRemove;

    /* Flag to note that the table is currently being destroyed - no action should be taken */
    oSettings.bDestroying = true;

    /* Fire off the destroy callbacks for plug-ins etc */
    _fnCallbackFire( oSettings, "aoDestroyCallback", "destroy", [oSettings] );

    /* If the table is not being removed, restore the hidden columns */
    if ( !bRemove )
    {
    for ( i=0, iLen=oSettings.aoColumns.length ; i
  • allanallan Posts: 63,106Questions: 1Answers: 10,394 Site admin
    Does this leak also occur in the 2.1.6-dev version of TableTools: http://datatables.net/download . I think this might already have been addressed.

    Thanks,
    Allan
This discussion has been closed.