Memory Leak in IE with XMLHttpRequest

K

Keenan

Is the IE browser in Windows CE 5.0 based on a version of the regular
IE? I am experiencing memory leaks using CE that don't occur under my
IE6 browser. I've found older posts on similiar issues with IE but
nothing recently and nothing for CE.

I am using JavaScript and an XMLHttpRequest Object to update dynamic
data on a page. The web server is a CE device. Serving it to a PC, no
memory leaks are observed on either device. Serving the page to itself
(localhost), IE consumes its 32 MB of memory in 10-15 minutes and then
I get an "Out of Memory at Line xx" error. I have noticed that the
Google Suggest site (also uses XMLHttpRequest) appears to leak when I
browse from the CE device.

If someone has a CE browser and would like to see for themselves, I can
provide a link to the device.

Thanks!
 
J

John Spaith [MS]

I'm the MSXML owner and I've just spoken with the IE owner and neither of us
is familiar with this problem. I'm not sure what types of tools that
Windows CE ships externally for checking memory leaks, but it may be
worthwhile to see if any these are available. (I'm thinking appverifier in
particular.) They could at least give call stacks to isolate the problem --
it could be in jscript, msxml, wininet, urlmon, ...

You may also end up having to contact MS support on this one --
http://support.microsoft.com.

I'm sorry I can't provide more concrete steps to help you here, since this
one baffles me. I know a lot of people use XMLHTTP so if it was this badly
broken in every scenario we'd have heard about it by now, but I don't know
what it is you're doing differently.

--
John Spaith
Software Design Engineer, Windows CE
Microsoft Corporation

Check out the new CE Networking Team Blog at http://blogs.msdn.com/cenet/.

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. © 2003 Microsoft Corporation. All rights
reserved.
 
K

Keenan

John,
Thank you for your reply.

Just to confirm my observation, would you be willing to check out
linium.doboy.com ? If you browse to this site with a CE device, I
would expect you to see your memory grow (System Properties->Memory).

It should do it using Google Suggest as well but that's a much slower
process.

Searching the newsgroups, It seems that this issue was prevalent a few
years ago in IE, so I was thinking that the fixes just never made it to
CE 5.0.

I'll check into available tools for debugging/isolating the issue.
 
K

Keenan

Update: After running it overnight on my PC, I also get any out of
memory error.
 
K

Keenan

Update #2: Running the PC overnight creates a different out of memory
condition. It appears to be for the ASP portion and it is the CE
Device that runs out of memory. Oh goody......I love chasing multiple
problems.

BTW, I am somewhat of a newbie to the web technologies (html,
Javascript, ASP). My background is embedded systems (where I have
TOTAL control). Translation: Don't assume anything.

I will continue with Johns advice and use some of the tools to try and
isolate the issues and post my findings.
 
J

John Spaith [MS]

Hmm... I'm wondering if you're seeing it on your PC if that means that
invalid JScript is the root of the problem. Being an embedded guy myself I
definitely don't like dealing with JScript as much as C so I'm not sure if
this is some sort of leak on its side.

Unfortunately we're in the middle of a firedrill so I have no time to
actually try to repro this on my setup or do further investigation for you.
If other sources don't help, you may have to go to microsoft support.

Sorry I can't be of more help.

--
John Spaith
Software Design Engineer, Windows CE
Microsoft Corporation

Check out the new CE Networking Team Blog at http://blogs.msdn.com/cenet/.

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. © 2003 Microsoft Corporation. All rights
reserved.
 
K

Keenan

I've created a simple test to isolate the problem. I have also
monitored IE (iesample.exe) using Appverifier. I have two simple html
files on the CE Device (the web server)
Xml.htm contains the following:
<html>
<head>
</head>

<body onload="updateXml(0);">
<form name="form1">
Counter and Response:
<textarea name="xmlResponse" cols=80 rows=10></textarea>
xmlHttpRequest Ready State:
<input name="readystate">
Update Interval (milliseconds):
<input name="interval" value="1000">
</form>
<script language="JavaScript">
var xmlObj=null;
var count = 0;

function updateXml(input)
{
var url;
url = "RealtimeXml.htm?Param=" + input;
xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
xmlObj.onreadystatechange = processReqChange;
xmlObj.open("GET", url, true);
xmlObj.send(null);
}
function processReqChange()
{
document.form1.readystate.value = xmlObj.readyState;
if(xmlObj.readyState == 4)
{
document.form1.xmlResponse.value = count + "\n" +
xmlObj.responseText;
count++;
setTimeout("updateXml(" + count + ")",
document.form1.interval.value);
}
}
</script>
</body>
</html>

RealtimeXml.htm contains a single character.....the number "1".

Running this code I still consume memory. I ran it for two minutes
requesting data once per second (120 requests). Using Appverifier, I
see several handle leaks that say "Leaked 120 handles that were
allocated at this stack" Here is a call stack snippet from the log
file generated by AppVerifier for one such leak:
'CALL STACK
shim_hleak.dll! + 4546h
shim_hleak.dll! + 44bah
shim_hleak.dll! + 4853h
urlmon.dll! + 1954ch
urlmon.dll! + 1ae3ah
urlmon.dll! + 85ffh
msxml3.dll! + 789afh
msxml3.dll! + 77d01h
oleaut32.dll! + 7e29h
oleaut32.dll! + 1b029h
msxml3.dll! + 21582h
msxml3.dll! + 2164ch
msxml3.dll! + 4fc0ch
jscript.dll! + 1552ah
jscript.dll! + 16137h
jscript.dll! + 164eeh
jscript.dll! + 1542ch
jscript.dll! + 162d8h
jscript.dll! + 2aa56h
jscript.dll! + 1df68h
jscript.dll! + 18c87h
jscript.dll! + 162f3h
jscript.dll! + 2aa56h
jscript.dll! + 1df68h
jscript.dll! + 18c87h
jscript.dll! + 162f3h
jscript.dll! + 2aa56h
jscript.dll! + 1df68h
jscript.dll! + d510h
jscript.dll! + 18510h
jscript.dll! + 191a8h
jscript.dll! + 1694bh
mshtml.dll! + 101a8ch
mshtml.dll! + 10290eh
mshtml.dll! + 99830h
gwes.exe! + 1c958h
gwes.exe! + 1d588h
gwes.exe! + 184ech
coredll.dll! + 1017fh
iesample.exe! + 13eb1h
coredll.dll! + 150cfh
# LOGENTRY shim_hleak.dll 96 'Leaked 120 handles that were allocated at
this stack

I know I'm doing something stupid, just hard to sort out what it is
when you are crossing so many technologies. I'll see if I can take a
peak at the source code for the files mentioned above. I don't have
Platform Builder loaded, but I'll try and work with someone who does.
 
J

John Spaith [MS]

Yup - this is the typical really nasty IE problem where a bunch of huge DLLs
all interact with each other in strange ways.

I can save you the trouble as far as trying to get the source code for any
of this. For various reasons (partially IP, partially because they'd be so
darn hard to debug anyway) MS does not ship the source to JScript, MSHTML,
MSXML, URLMON, or COM. Sorry.

One suggestion is could you try setting "xmlObj=null" again at the end of
the function where you allocate it and try setting anything else to null
explicitly when done with it. I thought the vars should be GC's
automatically but it may not hurt to try.

Another suggestion is that if this reproes on desktop IE, then you're
probably not the first person to have hit this general pattern. You may try
reposting this on a new thread to an IE centric group (maybe retry
microsoft.public.windows.inetexplorer.ie6.browser with this simpler repro,
but in a new thread so you'll get new eyes on it.) There are not a lot of
browser gurus on the other newsgroups you're targetting -- I can say I'm not
one myself.

--
John Spaith
Software Design Engineer, Windows CE
Microsoft Corporation

Check out the new CE Networking Team Blog at http://blogs.msdn.com/cenet/.

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. © 2003 Microsoft Corporation. All rights
reserved.
 
K

Keenan

I don't see any sign of a memory leak when running it from my desktop.
I do see it if I call up the page from another CE device so to me that
isolates it to the client and not the server (which John already
eleuded to).

This thread is already being posted in
microsoft.public.windows.inetexplorer.ie6.browser, but I'll take your
advice and post a new thread. I think I would have had much better
luck in 2003. It seems like a lot of people ran into it on the desktop
back then (I wish I could find out the specifics of what has changed
since then). I'll also search the AJAX groups. I know they have
libraries and maybe the libraries have work-arounds for the issue.
I'll post my findings.
 
G

Guest

Keenan -

Found your post while Googling for CE xmlhttp memory leak. Fancy that.

I have a CE device (4.1) that also appears to be leaking a small amount of
memory for every new xmlhttp request. I found this article:
http://support.microsoft.com/kb/875507
Which made me fear I may need to go back to the CE hardware OEM.

Did you ever make any headway on this?
 
K

Keenan

I went back to the OEM. Here was the response:

News :
- Microsoft analyzed your demo project
- One reason for memory leak is your variable declaration...
But even after defining them as globals the mem leak is still existing
(but system does not loose mem so quick)
Result :
- Microsoft confirmed bug for CE5 (bug fix existing for CE4.2,
but no QFE for CE5)
- Today I am starting the procedure for getting a QFE for CE5

The updated xml code:
<html>
<head>
</head>

<body onload="updateXml(0);">
<form name="form1">
Counter and Response:
<textarea name="xmlResponse" cols=80 rows=10></textarea>
<br>
xmlHttpRequest Ready State:
<input name="readystate">
<br>
Update Interval (milliseconds):
<input name="interval" value="1000">
<br>
Test:
<input name="test">
</form>
<script language="JavaScript">
var xmlObj=null;
var count = 0;

function updateXml(input)
{
var url;
url = "RealtimeXml.htm?Param=" + input;

if (xmlObj == null)
{
document.form1.test.value = document.form1.test.value + "x";
xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlObj.abort();
xmlObj.onreadystatechange = processReqChange;
xmlObj.open("GET", url, true);
xmlObj.send(null);
}
function processReqChange()
{
document.form1.readystate.value = xmlObj.readyState;
if(xmlObj.readyState == 4)
{
document.form1.xmlResponse.value = count + "\n" +
xmlObj.responseText;
count++;
setTimeout("updateXml(" + count + ")",
document.form1.interval.value);
}
}
</script>
</body>
</html>


I am expecting a fix in early March. I will try and remember to post
the findings here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Memory leak on streaming media 2
Memory leak 1
XMLHttpRequest on a MAC's IE browser? 3
IE Memory Leak? 4
High Memory Usage for IE 2
Java script memory leak 2
Memory leak in an managed application 4
Memory Leak 1

Top