By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,028 Members | 1,080 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,028 IT Pros & Developers. It's quick & easy.

window.open() memeory leak in IE

P: n/a
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>
Aug 21 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

SPG wrote:
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
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 21 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.