New posting on MSDN about script leak patterns and how to fix them for anyone that builds dynamic web apps.

Over here on the IE team we take leaks seriously. Extremely seriously. This is contrary to the popular opinion, but I'll let you make your own informed decisions. My new posting on MSDN is specifically designed to help you identify and fix several patterns of leaks. These range from your basic circular reference to your more complex (and more popular) closure based leak. Hopefully this new material can help you identify and exterminate all of the leaks in your code. If you have questions about the article feel free to post here or over on the IE team blog and I'll try to respond to any non-flaming responses ;-)

MSDN: Leak Patterns in IE

Published Monday, June 20, 2005 5:46 PM by Justin Rogers

Comments

Tuesday, June 21, 2005 9:59 AM by Chris Slatt

# re: New posting on MSDN about script leak patterns and how to fix them for anyone that builds dynamic web apps.

Good to have you back! When do the posts on using Internet Explorer as a Game Engine start? ;)
Wednesday, June 22, 2005 3:57 AM by carter

# re: New posting on MSDN about script leak patterns and how to fix them for anyone that builds dynamic web apps.

very nice article, this will save a lot of people a lot of headaches :)

i do have one suggestion though, the images in the article are being resized by IE, leaving us with basically unreadable text. could you perhaps include a link to open them at full size in a new window? (i have sufficed with opening the image directly for now)

it would be nice if IE7 could do a "smart resize" on images the same way photoshop or paint shop pro resize images, instead or a pixel resize or bicubic resize or whatever its doing right now!
Wednesday, June 22, 2005 5:01 AM by Jon Boxall

# Required reading for anyone seriously considering AJAX

Great article - could have done with this 5 years ago...
Wednesday, June 22, 2005 5:38 PM by Andy Smith

# re: New posting on MSDN about script leak patterns and how to fix them for anyone that builds dynamic web apps.

Hey Justin,

Those leaks...
From my understanding from another msdn article (can't seem to find it now), any leaks caused by an element in a closure would be cleaned as soon as the user navigates to a new page. Is that correct?
Wednesday, June 22, 2005 8:27 PM by Justin Rogers

# re: New posting on MSDN about script leak patterns and how to fix them for anyone that builds dynamic web apps.

Image Sizes:
They should be fixed/getting fixed. They looked really good in Visio when I was making them. If they aren't fixed shortly I'll try and post alternates somewhere in addition.

Andy:
Closures leak across page navigations. The underlying problem is that there is a circular reference between an element in IE and a closure object in JScript. The only way to reclaim this memory is to recycle the process, so these shouldn't be taken lightly in production level script controls.
Thursday, June 23, 2005 9:06 AM by carter

# re: New posting on MSDN about script leak patterns and how to fix them for anyone that builds dynamic web apps.

the images themselves are fine when viewing them at full size (right-click -> properties on the image and get the direct URL), so you did a good job with making the images; it's just that viewing them in the article isn't that great because IE is scaling the images down due to explicit width/heights.

and since you're on the IE team, can you suggest the "smart" image scaling that i was talking about above? pixel/bicubic resizes look awful.
Saturday, July 02, 2005 6:41 PM by Nicolás Castagnet

# re: New posting on MSDN about script leak patterns and how to fix them for anyone that builds dynamic web apps.

Very good article!!

Take a look at http://jgwebber.blogspot.com/2005/05/drip-ie-leak-detector.html. There is a very useful tool developed by Joel Webber to detect memory leaks.

But, I have another memory leak problem (in IE6) and I don't know how to solve it. It is very simple to reproduce. Create a page with this code:

<html>
<body >
<iframe id="testframe" src="about:blank"></iframe>
</body>
</html>

Load it in the browser and press Refresh several times (or use the function 'Blow Memory' in the tool that I mentioned above). Also happens if you define a loop that changes the page in the frame, for example:

var f = document.getElementById("testframe");
for (var i = 0; i < 10000; i++)
f.src = "about:blank"

I will appreciate a lot if someone could give me a clue to resolve this problem, or confirms me that it is a bug.

Thanks,
Nicolás Castagnet (ncastagnet@dlya.com.uy)
Tuesday, July 05, 2005 8:36 PM by eeevans

# re: New posting on MSDN about script leak patterns and how to fix them for anyone that builds dynamic web apps.

Hey, did the source for the Terrarium ever get released?
Thursday, July 14, 2005 6:05 PM by Anonymous

# re: New posting on MSDN about script leak patterns and how to fix them for anyone that builds dynamic web apps.

In the long run, the best way to remove these leaks would be a fully managed (and thus, garbage-collected) web browser implementation. Since it would have other advantages (improved security, more flexibility to implement some of the weirdest ideas out of the W3C), it hope the IE team will investigate this possibility.
Maybe the development model for the IPv6 stack (first a project at MS Research, then integration into the mainstream product) could serve again (hopefully faster)?
Monday, July 18, 2005 7:38 PM by Martin

# re: New posting on MSDN about script leak patterns and how to fix them for anyone that builds dynamic web apps.

Very nice and well written article. Congrats.

But as IE7 is moving towards standards complience, it would be better not to use the long-time-ago depreciated "language" attribut of the script tag.

So <script type="text/javascript"> and not <script language="JScript">

Bye,
Martin
Tuesday, June 05, 2007 12:04 AM by Silvanos

# re: New posting on MSDN about script leak patterns and how to fix them for anyone that builds dynamic web apps.

Interesting...

Sunday, June 10, 2007 1:50 PM by Leonidas

# re: New posting on MSDN about script leak patterns and how to fix them for anyone that builds dynamic web apps.

Sorry :(

Monday, June 11, 2007 10:14 PM by Kosmas

# re: New posting on MSDN about script leak patterns and how to fix them for anyone that builds dynamic web apps.

Cool.

Leave a Comment

(required) 
(required) 
(optional)
(required)