I'm trying to replace a DOM element (a div) using Prototype's Element.replace() operation. It seems to do the replacement OK, but leaks a single DOM node in the process. I checked this with sIEve; all but one of the existing DOM elements is freed by the innerHTML="" bit. This is in turn leaking memory, which I can't afford in a long-running application. Here's what I'm doing at present:
var stats = $('stats');
var newStats = $('i_stats');
stats.innerHTML = "";
stats.replace(newStats);
newStats.id = 'stats';
stats = null;
newStats = null;
'stats' is the old div, which contains a table. 'i_stats' is the new div, which has been AJAXed in along with some other unrelated bits (which aren't the source of the leak; the leak still happens if I omit these).
I must be doing something wrong here; please enlighten me!