解决Js内存泄漏问题的代码片断
是从国外的一个网站上抄回来的。
Js内存泄漏,在IE里面好像没什么影响,但是如果在应用程序中使用了js脚本,问题就大了,特别是如果在Office插件里面的HtmlView控件里面的Js脚本,Office应用程序就突然退出了。
function ReleaseEvents()
{
var events = ["focus", "blur", "change", "click", "mousedown",
"mouseup", "mouseover", "keypress", "keydown",
"keyup", "keypress"];
![](/Images/OutliningIndicators/InBlock.gif)
var helper = function(obj)
{
var i;
for (i = 0; i < events.length; i++)
obj["on" + events[i]] = null;
for (i = 0; i < parent.childNodes.length; i++)
helper(parent.childNodes[i]);
}
![](/Images/OutliningIndicators/InBlock.gif)
helper(document);
}
window.onunload = ReleaseEvents;
Js内存泄漏,在IE里面好像没什么影响,但是如果在应用程序中使用了js脚本,问题就大了,特别是如果在Office插件里面的HtmlView控件里面的Js脚本,Office应用程序就突然退出了。
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](/Images/OutliningIndicators/None.gif)