.remove()
just removes the element from the DOM, if anything is still referencing it (in your code) it will not be Garbage Collected.
Edit
Yes the .remove()
is the correct way of detaching/removing it from the DOM, but it is still held in memory because other things are referencing it (knockout's internals in this example).
One way, and the way I do it, is to keep a collection of all the high-level DOM elements that I create in my controls, then have a destroy function that loops these and calls .remove()
on them and assigns them to null
E.g (Note this is held within each control object (no leaky global stuff):
var elements =
{
'table' : $('#some_table'),
'button' : $('#some_button')
};
function destroy()
{
for(var key in elements)
{
elements[key].remove();
elements[key] = null;
}
}
You may be able to take this approach with knockout.