473,766 Members | 2,060 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Handle Leaks with Microsoft.XMLDO M

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\M icrosoft\Window s\CurrentVersio n\Internet
Settings\ZoneMa p

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("P OST", "<URL>" //where <URL> is the url that is
responding with xml data
xmlhttp.onready statechange=fun ction()
{
if (xmlhttp.readyS tate==4)
{
responseXML = xmlhttp.respons eText;
xmlDoc = new ActiveXObject(" Microsoft.XMLDO M");
xmlDoc.loadXML( responseXML);

for (i=0; i<xmlDoc.docume ntElement.attri butes.length;
i++)
{
currentId =
xmlDoc.document Element.attribu tes[i].nodeName;

document.getEle mentById(curren tId).innerHTML =
null;
document.getEle mentById(curren tId).innerHTML =
xmlDoc.document Element.attribu tes[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(nu ll);
delete xmlhttp;
xmlhttp = null;

Nov 23 '05 #1
39 7436
VK

ty*****@gmail.c om wrote:
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\M icrosoft\Window s\CurrentVersio n\Internet
Settings\ZoneMa p

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. 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.

Nov 23 '05 #2
VK, thanks for the reply.

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

Any other ideas anyone?

Nov 28 '05 #3
VK
> ty*****@gmail.c om wrote:
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:


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++;
$('out').innerH TML = content;
document.forms[0].elements[0].value = counter;
// IE doesn't operate with the real time but with
// system ticks - 60ms per tick
// so setTimeout(..., 0,10,25,59) all means 60
setTimeout('fun ()');
}

function fun() {
var spice = '?' + (new Date()).getTime ();
// You may guess that "data.xml" should be provided:
$('loader').
startDownload(' data.xml'+spice , onDownloadDone) ;
}

function $(id) {
return document.getEle mentById(id) || null;
}
</script>

<style type="text/css">
body { background-color: #FFFFFF}
</style>

</head>

<body onload="fun()">

<IE:Download id="loader" style="behavior :url(#default#d ownload)" />

<div id="out">&nbsp; </div>

<form>
Loops: <input type="text" name="cnt">
</form>

</body>
</html>
On my test Win98 SE / IE 6.0 it held 3,000 loops like no problem. I
just cannot reserve the computer for the entire day to see the
"work-on-denial" limit but it's definitely not 30-40 loops like in your
case. You have to improve your algorithm I guess.

Nov 28 '05 #4
Thanks VK, I'll test out that code and see how it goes on the test
machine.

Just some additional info: My original code does NOT have handle leaks
on most machines, but it does on a few. The system info for the
problematic machine is:

Windows XP SP2
IE version: 6.0.2900.2180.x psp_sp2_gdr.050 301-1519

Thanks again for that sample. Unfortunately, the code needs to support
firefox, mozilla, and opera, so I'm not sure if the xmlns:IE and the
IE:Download tags will be supported... but I'll give it a shot and let
you know.

Thanks,
--Mike

Nov 28 '05 #5
VK

tydbowl wrote:
Thanks VK, I'll test out that code and see how it goes on the test
machine.

Just some additional info: My original code does NOT have handle leaks
on most machines, but it does on a few. The system info for the
problematic machine is:

Windows XP SP2
IE version: 6.0.2900.2180.x psp_sp2_gdr.050 301-1519

Thanks again for that sample. Unfortunately, the code needs to support
firefox, mozilla, and opera, so I'm not sure if the xmlns:IE and the
IE:Download tags will be supported... but I'll give it a shot and let
you know.


Behaviors are IE-exclusive, so it will not work for Firefox or Opera.

I gave this code to narrow the possible leak source: <download>
behavior doesn't leak for sure for IE 5.5 and higher. I just checked it
on Windows XP SP1 for 5,000 loops.

So you may want to run this sample exactly as it is on the machines of
question to see their work-on-denial limit. If it still crashes any
soon then the problem is:
1) either in the JScript / MSXML behavior difference
2) or in some DOM holes (for example innerHTML was known to be leaky -
but long time ago).

JScript has special versioning methods:
alert(ScriptEng ineMajorVersion () + '.' + ScriptEngineMin orVersion())
will give you the actual JScript version running on the machine.

Compare it.

If the machine of the question has a lower version, update JScript
from:
<http://msdn.microsoft. com/library/default.asp?url =/downloads/list/webdev.asp>

Nov 28 '05 #6
The code sample provided does not leak. But then again,when I comment
out the line of code next to the "Note:" in my original sample, the
leaks also dissappear.

It appears the leaks only occur when I set the innerHTML to the value
of an XMLDOM node.

Also I checked the JScript version as you suggested. Both leaky and
non leaky machines print out "5.6" (.... Though I'm admittedly not
sure if the JScript version is the samething as the javascript
version... I don't know enough about the two terms to know if they are
really different under the covers).

I'm going to play with that sample and replace the "$('out').inner HTML
= content;" line with the XMLDOM code from the original sample and see
if the leak occurs. I presume it will.

Nov 28 '05 #7
VK

tydbowl wrote:
Though I'm admittedly not
sure if the JScript version is the samething as the javascript
version... I don't know enough about the two terms to know if they are
really different under the covers).
Mozilla Foundation (and many others) is going by the conventional
versioning where JavaScript 1.0 is the first one in Netscape 2.x and
JavaScript 1.5 is the current one.

ECMA docs are based on the description of Netscape 4.? (don't remember
- 4.5 or something) They have something atop of 1.2 and something
missing from 1.3 (minus all Netscape stuff ECMA considered to be not
enough academical). So it's kind of 1.2+/- or 1.3-- :-)

Microsoft mainly goes by Internet Explorer versions: so JScript 5.5 was
first shipped with IE 5.5.
*Approximately* JavaScript 1.5 corresponds to JScript 5.5 (keeping in
mind all browser-specific features) and this was the basic ground for
several last years.
I'm going to play with that sample and replace the "$('out').inner HTML
= content;" line with the XMLDOM code from the original sample and see
if the leak occurs. I presume it will.


May I see what are you actually inserting into innerHTML?
You may put any foobar text content but keep all tags

Nov 28 '05 #8
VK wrote:
tydbowl wrote:
Though I'm admittedly not
sure if the JScript version is the samething as the javascript
version... I don't know enough about the two terms to know if they are
really different under the covers).
Mozilla Foundation (and many others) is going by the conventional
versioning where JavaScript 1.0 is the first one in Netscape 2.x and
JavaScript 1.5 is the current one.


What "convention al versioning" are you talking about? JavaScript is an
independent language implementation, of course its versioning is different
than other (ECMAScript) implementations .
ECMA docs are based on the description of Netscape 4.? (don't remember
- 4.5 or something) They have something atop of 1.2 and something
missing from 1.3 (minus all Netscape stuff ECMA considered to be not
enough academical). So it's kind of 1.2+/- or 1.3-- :-)
Nonsense. As the ECMAScript Specification and the JavaScript Guide(s)
state,

- ECMAScript 1 was based on JavaScript 1.1 (NN3) and JScript 1.0 (IE3).
- JavaScript 1.2 (NN 4.0-4.05) is not fully compatible with ECMAScript 1.
- JavaScript 1.3 (NN 4.06-4.8) is fully compatible with ECMAScript 1.
- JavaScript 1.4 (not implemented to my knowledge) is fully compatible
with ECMAScript 1.
- JavaScript 1.5 (Mozilla/5.0 browsers incl. NN6) is fully compatible
with ECMAScript 3.
- JavaScript 1.6 (Mozilla/5.0 rv:1.8b+ browsers incl. upcoming Firefox 1.5)
is probably fully compatible with ECMAScript 3 (CMIIW).

Unfortunately, there is no such compact description for JScript versions in
the MSDN Library. However, Microsoft explicitly states several features in
JScript (.NET) not to be "ECMAScript compliant" or "not provided by the
ECMAScript language":

<URL:http://msdn.microsoft. com/library/en-us/script56/html/js56jsoriVersio nInformation.as p>
<URL:http://msdn.microsoft. com/library/default.asp?url =/library/en-us/jscript7/html/jsgrpnonecmafea tures.asp>
Microsoft mainly goes by Internet Explorer versions: so JScript 5.5 was
first shipped with IE 5.5.
True, however unlike JavaScript versions, JScript versions are independent
of the browser version in a way that the Script Engine can be upgraded
independently. Hence JScript 5.5 is the minimum version that can be
expected on IE 5.5 _for Windows_ (there appears to be a difference in
script support between in IE versions for Windows and IE versions for Mac).
*Approximately* JavaScript 1.5 corresponds to JScript 5.5 (keeping in
mind all browser-specific features) and this was the basic ground for
several last years.


That remains to be seen. I do not think you have the knowledge required to
assess that. Neither have I yet, however I think my feature support matrix
on <URL:http://www.pointedears .de/scripts/js-version-info> will allow me to
assess that once it is complete.
PointedEars
Nov 28 '05 #9
VK wrote:
<snip>
ECMA docs are based on the description of Netscape 4.?
(don't remember - 4.5 or something) They have something
atop of 1.2 and something missing from 1.3 (minus all
Netscape stuff ECMA considered to be not enough academical).
So it's kind of 1.2+/- or 1.3-- :-)

<snip>

I realise that you consider the stories in your head as more true than
anything else, but do you really think that it does anyone any good at
all for you to be posting this pack of lies?

Richard.
Nov 29 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1132
by: Saravanan D | last post by:
Hello, I have python module which uses C++ extension modules. If I run the Python Module for a long time in an windows environment, Perfmon shows handle leaks in Python.exe. Is there any way to detect it ? Thanks in Advance. Saravanan D
3
1524
by: Ray | last post by:
Hi, Al There is a xml file, I want to read/write it in ASP. As following source code, dim objXm Set objXML = Server.CreateObject("Microsoft.XMLDOM" objXML.async = Fals objXML.load server.mappath("../online.xml" If objXML.parseError.errorCode <> 0 The response.write "parse online.xml error(" & xsl & ") response.en End I
2
1989
by: jfizer | last post by:
I have a web app that uses a form with its fields populated from XML using Microsoft.XMLDOM. The problem is that Microsoft.XMLDOM functions seem to run on their own thread, so I dont know when the fields are done populating. Can anyone think of a way for me to check when the following function finishes? function importXML(xmlQuery,xmlSrc,xmlTarget) {
0
3907
by: Frank Lopez | last post by:
Does anyone know if Microsoft generated a whitepaper on this topic? Does anyone know what the solution is? (meaning, eliminate the leak problem -- I am seeing three memory leaks from dllmodul.cpp(102) similar to what is mentioned below)... I am calling MFC as part of unmanaged code used by the managed code. +--------
7
1824
by: Ken Varn | last post by:
I am working in managed C++. I have a Mutex object in which I need to replace the Handle property with a new handle. The new handle is being constructed using Win32 CreateMutex call. I need to call the Win32 version in order to set the security descriptor for the mutex, which is not natively supported in .NET Framework 1.1. I always get a little nervous about resource leaks when trying to bridge Win32 with .NET, so I want to make sure...
0
2066
by: =?Utf-8?B?TWF0dCBDYWxob29u?= | last post by:
HI there, I am getting an error on my page which calls up a web service. Microsoft VBScript runtime error '800a13ba' Unknown runtime error: 'SearchQueryXML' /SearchResults.asp, line 142
2
35620
weaknessforcats
by: weaknessforcats | last post by:
Handle Classes Handle classes, also called Envelope or Cheshire Cat classes, are part of the Bridge design pattern. The objective of the Bridge pattern is to separate the abstraction from the implementation so the two can vary independently. Handle classes usually contain a pointer to the object implementation. The Handle object is used rather than the implemented object. This leaves the implemented object free to change without affecting...
1
6764
by: =?Utf-8?B?QU1lcmNlcg==?= | last post by:
I have a vb.net program that leaks handles as reported by task manager. After running for a couple of hours, task manager reports over 1000 handles, and it continues to grow. I think I am failing to close or dispose something. I've looked at the code and can't spot the problem. The program is fairly big (10k lines). I can ask it to do something that always increases the handle count, so the problem is reproducible. What I don't know...
1
4225
AnuSumesh
by: AnuSumesh | last post by:
Hi, I want to read the text property of XML file. My xml file is as follows: <?xml version="1.0"?> <Domain_Credentials> <User> anu </User>
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10008
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9837
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8833
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6651
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.