DataTables / TableTools

Please note that TableTools has now been retired and replaced by the Buttons and Select extensions which offers significant improvements and API integration with the rest of DataTables and the other extensions.
http://datatables.net/
Other
237 stars 149 forks source link

IE Memory leak with ZeroClipboard_TableTools (fix included) #100

Closed distributedlock closed 9 years ago

distributedlock commented 9 years ago

Hi,

There is a memory leak that occurs in IE 9 (possibly IE9 and below), I have not tested this with IE9+. The leak only occurs in the IE suite. I have tested this in Chrome and Chrome's garbage collector handles it properly.

This issue occurs when you destroy a DataTable-ized and TableTools-ized table using tableName.destroy() function and again redraw the table by initializing DataTable again with TableTools buttons. We are reinitializing a table multiple times in a single page and every time a DT TableTools init occurs, the whole table info including DOM tree is stored in ZeroClipboard_TableTools.clients object. Now, when an old table is deleted, Chrome's gc will know that the deleted clients in ZeroClipboard_TableTools.clients are no longer being used and purge from memory. IE doesn't know that (because it's gc is terrible) so, the memory usage gradually keeps rising.

Fix for this issue: ZeroClipboard_TableTools.clients = {}; by forcefully emptying clients that are no longer present in the DOM which will trigger IE's gc to purge from memory.

Maybe table.destroy() function can remove dead clients in ZeroClipboard when DataTables and TableTools are integrated? This might be a better fix than the way I am doing it.

DataTables commented 9 years ago

Thanks for pointing that out!

Interesting that the other GCs will clean this up - looking at it, that is a nasty little bug that I'm somewhat surprised the other GCs do pick up!

It is worth noting that TableTools is shortly to be replaced by two new extensions - Buttons and Select. So it might be a while before this bug is in a released version of TableTools. I'll likely wait a month or two after the new plugins are released (this method) and the issue a final bug fix release of TableTools.

distributedlock commented 9 years ago

No problem.

Yeah, it was a little odd how the new GCs (Firefox, Chrome) are cleaning it up properly and IE wasn't.

Thank You for your commit, I can confirm the memory leak no longer exists with the version based on your commit in the IE suite.