Do you need to call fnDestroy()?

Do you need to call fnDestroy()?

robertbrowerrobertbrower Posts: 158Questions: 1Answers: 0
edited November 2013 in Plug-ins
If you have a container that contains a table and create a datatable from the table, then using ajax, replace the contents of the container with a new table, do you need to at any point call fnDestroy on the original datatable before initializing the new one? And if you don't will there be any memory leaks? Thanks. Robert.

Replies

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin
    Yes - if you remove the old table, you should destroy it. If you are just replacing the data it is more efficient to use fnClearTable and fnAddData - but if you are completely changing the table, yes you will need to destroy the old one before adding the new. Otherwise, as you say you'll get a memory leak since the browser still has events attached to nodes, preventing those nodes from being garbage collected.

    Allan
This discussion has been closed.