我搜了一下网络,都说下面这样写有效果:
/**
- 加载iframe时使用的方法,防止内存泄漏
/
function loadIframe($frame , url){
var ifParent = $frame.parent();
if($frame[0]){
$frame.unbind(); //remove listeners on document $frame.find('').unbind(); //remove listeners on all nodes $frame[0].src = 'about:blank';
$frame[0].contentWindow.document.write('')
$frame[0].contentWindow.document.close();
$frame.remove();
if( typeof CollectGarbage == "function") { CollectGarbage(); } }
$('').appendTo(ifParent); }
但是我用chrome的profile调试发现还是不理想,每次点击一下菜单,改变iframe的src会增加20M左右的内存,有没有更好一点的办法?