Possible Duplicate:
jQuery memory leak with DOM removal
I created a simple javascript code snippet to test memory leak.
function createDom(howmany)
{
var i;
var el;
var body = $("body");
for(i=0;i<howmany;i++)
{
el = $("<div></div>");
el.text(i);
el.addClass('element');
body.append(el);
}
}
$(document).ready(function(){
createDom(10000)
});
when i opened the file in Chrome, it uses about 20mb. When I move to a new url (about:blank), Chrome clears up the memory.
The problem is that Chrome uses more memory when I execute $(".element").remove(). The bigger problem is that the memory stays even if I change the URL.
Am I testing it incorrectly? I almost feel like I should just hide all the element instead of removing them...