window.open() memeory leak in IE

S

SPG

Hi,

We are seeing a strange memory leak in IE (6...any) with opening and closing
windows using JS
When you run the code below (Assuming you have another file called
leak2.html) the process manager shows and increase of about 150K in mem.
Then when you close the new popup down only 75K is cleared up.

We noticed this when we have a very large XML DOM being loaded into a
window, about 1meg big. When the window is closed on 500K is being cleaned
up. Therefore we have a rather large memory leak as this window is required
in many places.

Any ideas what could cause this?

Steve

<html>
<head>
<script>
function clickButton() {

window.open('leak2.html', '', 'width=500, height=400');
}
</script>
</head>
<body>
<button id="btn" onclick="clickButton()">Click me!</button>
</body>
</html>
 
L

Laurent Bugnion

Hi,
Hi,

We are seeing a strange memory leak in IE (6...any) with opening and closing
windows using JS
When you run the code below (Assuming you have another file called
leak2.html) the process manager shows and increase of about 150K in mem.
Then when you close the new popup down only 75K is cleared up.

We noticed this when we have a very large XML DOM being loaded into a
window, about 1meg big. When the window is closed on 500K is being cleaned
up. Therefore we have a rather large memory leak as this window is required
in many places.

Any ideas what could cause this?

Steve

<html>
<head>
<script>
function clickButton() {

window.open('leak2.html', '', 'width=500, height=400');
}
</script>
</head>
<body>
<button id="btn" onclick="clickButton()">Click me!</button>
</body>
</html>


Keep a reference to the newly opened window, and when you close it (or
reopen it), set the reference to null. That way the garbage collector
will collect (eventually) the window object. If you don't, the window
object stays in the memory, and noone know when it will be deleted.

Additionally, you should always name your windows (but that has nothing
to do with your problem).

<html>
<head>
<script>
var wPopUp = null;
function clickButton()
{
if ( wPopUp )
{
if ( !wPopUp.closed )
{
wPopUp.close();
}
wPopUp = null;
}

wPopUp = window.open('leak2.html',
'wPopUp', 'width=500, height=400');
}
</script>
</head>
<body>
<button id="btn" onclick="clickButton()">Click me!</button>
</body>
</html>

HTH,
Laurent
 

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

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top