我已经为Windows边栏写了一个小工具。这基本上意味着它是一个微型网页,运行数月。如何识别,修复,关闭Windows边栏小工具中的内存泄漏?
几个星期后,安装第三方小工具的sidebar.exe进程的内存使用量(工作集)运行到数百兆字节。
没有办法确定内存泄漏的来源,我只是假设它是传闻中的XMLHttpRequest关闭问题。虽然在我的情况下,我不是在异步做它。所以我想这只是JAX而不是A JAX。
涉及网络命中JavaScript函数:
function FetchXML(method, url)
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{ // Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
throw "XMLHttp not supported"
}
}
}
xmlHttp.open(method, url, false);
xmlHttp.send(null);
if (xmlHttp.status != 200)
{
throw "Server returned status code "+xmlHttp.status.toString();
}
if (xmlHttp.responseXML.parseError.errorCode != 0)
{
throw "Error in returned XML: "+xmlHttp.responseXML.parseError.reason;
}
var responseXML = xmlHttp.responseXML;
xmlHttp = null;
return responseXML;
}
这是否看起来它可能永远不会出现内存泄漏的来源是什么?
我担心如果没有真正的关闭,我会回到原点。
您可以用“xmlHttp = new XMLHttpRequest();”替换您的整个Try Catch语句。只有IE引擎用于显示小工具。 – ZippyV 2009-08-02 13:56:59