使用Microsoft.XMLDOM处理泄漏 [英] Handle Leaks with Microsoft.XMLDOM

查看:59
本文介绍了使用Microsoft.XMLDOM处理泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个问题,下面的代码块会导致某些机器上的句柄泄漏。泄漏APPEARS将处理注册表项:


HKCU \Software \ Mysoftoft \ Windows \ CurrentVersion \Int ernet

设置\\ \\ _ZoneMap


下面的代码运行在每秒运行几次的计时器上,大约15-30分钟左右后,它就会耗尽
崩溃IE浏览器。


我在msdn上发现了一篇文章,讨论如果在
的方式设置属性可能会导致内存泄漏/>
div在离开页面之前不会设置为null(他们建议在卸载函数中执行此操作

,当然,这在这里不太有用

因为我们没有卸货......我们只是不断更新数据。


相反,正如你在下面看到的那样,我已经设置了重置之前div的innerHTML为null

....无济于事。任何帮助都会很多

赞赏。


- 麦克风


var currentId;

var responseXML;

var xmlDoc;

var xmlhttp = new ActiveXObject(" Msxml2.XMLHTTP");

xmlhttp.open(" POST","< URL>" //其中< URL>是使用xml数据回复
的网址

xmlhttp.onreadystatechange = function()

{

if(xmlhttp.readyState == 4)

{

responseXML = xmlhttp.responseText;

xmlDoc = new ActiveXObject(" Microsoft.XMLDOM");

xmlDoc.loadXML(responseXML);


for(i = 0; i< xmlDoc.documentElement.attributes.length;

i ++)

{

currentId =

xmlDoc.documentElement.attributes [i] .nodeName;


document.getElementById(currentId).innerHTML =

null;

document.getElementById(currentId).innerHTML =

xmlDoc.documentEl ement.attributes [I] .nodeValue; //注意:

注释掉这一行会删除句柄泄漏....但是当然

也会阻止我的数据更新。

}

删除xmlDoc;

xmlDoc = null;

responseXML = null;

}


xmlhttp.send(null);

删除xmlhttp;

xmlhttp = null;

I have a problem where the below code chunk causes handle leaks on some
machines. The leak APPEARS to be handles to the registry key:

HKCU\Software\Microsoft\Windows\CurrentVersion\Int ernet
Settings\ZoneMap

The below code runs on a timer running several times per second and
after about 15-30 minutes or so, it runs out of handles and crashes IE.

I found an article on msdn discussing how setting properties in this
way could cause memory leaks if the reference to the nodeValue in the
div isn''t set to null before leaving the page (they suggest doing this
in an unload function though of course, that does not quite work here
since we aren''t unloading... we''re just constantly updating the data).

Instead, as you can see below, I''ve set the div''s innerHTML to null
prior to resetting it.... to no avail. Any help would be much
appreciated.

--Mike

var currentId;
var responseXML;
var xmlDoc;

var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
xmlhttp.open("POST", "<URL>" //where <URL> is the url that is
responding with xml data
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4)
{
responseXML = xmlhttp.responseText;
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.loadXML(responseXML);

for (i=0; i<xmlDoc.documentElement.attributes.length;
i++)
{
currentId =
xmlDoc.documentElement.attributes[i].nodeName;

document.getElementById(currentId).innerHTML =
null;
document.getElementById(currentId).innerHTML =
xmlDoc.documentElement.attributes[i].nodeValue; //Note:
Commenting out this line removes the handle leak.... but of course that
also prevents my data from updating.
}
delete xmlDoc;
xmlDoc = null;
responseXML = null;
}

xmlhttp.send(null);
delete xmlhttp;
xmlhttp = null;

推荐答案


ty*****@gmail.com 写道:
我有一个问题,下面的代码块导致一些机器上的句柄泄漏。泄漏APPEARS将处理注册表项:

HKCU \Software \ Microsoft \ Windows \ CurrentVersion \Int ernet
设置\ ZoneMap

我发现了一篇文章msdn讨论如果在离开页面之前
div中对nodeValue的引用没有设置为null,那么以这种方式设置属性如何导致内存泄漏(他们建议这样做
)一个卸载功能,当然,这在这里不太有用
因为我们没有卸载...我们只是不断更新数据。

相反,当你我可以看到,在重置之前我已经将div的innerHTML设置为null
....无济于事。任何帮助都会很受欢迎。
I have a problem where the below code chunk causes handle leaks on some
machines. The leak APPEARS to be handles to the registry key:

HKCU\Software\Microsoft\Windows\CurrentVersion\Int ernet
Settings\ZoneMap

The below code runs on a timer running several times per second and
after about 15-30 minutes or so, it runs out of handles and crashes IE.

I found an article on msdn discussing how setting properties in this
way could cause memory leaks if the reference to the nodeValue in the
div isn''t set to null before leaving the page (they suggest doing this
in an unload function though of course, that does not quite work here
since we aren''t unloading... we''re just constantly updating the data).

Instead, as you can see below, I''ve set the div''s innerHTML to null
prior to resetting it.... to no avail. Any help would be much
appreciated.




1.如果您的表单内容允许,请尝试从POST方法切换

到GET并使用send(")或(next to try)send(/ * nothing * /)而不是

send(null)


2.尝试为待处理的请求创建一个全局计数器并且不要让它

超过某个限制:每个新请求增加,每个减少

成功的要求。


我敢打赌#2是真正的问题,但如果我错了就不要杀人。



1. If your form''s content allows that, try to switch from POST method
to GET and use send("") or (next to try) send(/*nothing*/) instead of
send(null)

2. Try to make a global counter for pending requests and do not let it
go over some limit: increase on each new request, decrease on each
successful request.

I would bet on #2 as the real problem but don''t kill if I''m wrong.


VK,感谢您的回复。


我尝试了所有这些选项,但仍然发生泄漏。


还有其他任何想法吗?

VK, thanks for the reply.

I tried all of these options and the leak still occurs.

Any other ideas anyone?


> ty*****@gmail.com 写道:
我有一个问题,下面的代码块导致一些机器上的句柄泄漏。泄漏APPEARS将处理注册表项:
I have a problem where the below code chunk causes handle leaks on some
machines. The leak APPEARS to be handles to the registry key:



好​​的:首先让我们缩小问题范围:泄漏在哪里

出现:在IXMLHTTPRequest或DOM方法中。


忘记关于AJAX的一秒钟 - 你真的不需要它在IE中。

更可靠,更方便的下载行为(内置自

5.0)


< html xmlns:IE> ;

< head>

< title>测试< / title>

< meta http-equiv =" Content-Type" ; content =" text / html;

charset = iso-8859-1">

< script type =" text / javascript">


var counter = 0;


函数onDownloadDone(内容){

counter ++;



OK: first of all let''s us narrow the problem: where does the leak
occur: in IXMLHTTPRequest or in DOM methods.

Forget for a second about AJAX - you don''t need it really in IE. There
is much more reliable and convenient download behavior (build-in since
5.0)

<html xmlns:IE>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script type="text/javascript">

var counter = 0;

function onDownloadDone(content) {
counter++;


这篇关于使用Microsoft.XMLDOM处理泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆