views:

583

answers:

3

I browse to a web page that has a javascript memory leak. If I refresh the page multiple times, it will eventually use up a significant amount of memory, and javascript on the page will slow down. On this particular page, I notice a very significant slow down when IE gets up to 100MB of RAM, even though I have multiple GB free.

My question is why should leaked objects cause javascript to run slowly? Does anyone have any insight into how the JS interpreter in IE is designed, such that this happens?

A: 

Most programs get slower as they leak memory, either because they themselves get slower, or because the OS spends more time swapping and less time servicing the app. I'd be surprised if IE were an exception.

Paul Tomblin
'I have multiple GB free' == I really hope windows doesn't swap when it doesn't need to.
Kent Fredric
A: 

I would imagine that a memory leak could result in some memory fragmentation, which could slow the application down. I'm not sure about how this works, but is it possible that parts of the js code are still running in the background - as orphaned processes? This could explain the slowdown - as the page gets busier and busier, while you're not actually seeing the old copies running.

I could be pulling that out of my ass though.

rwmnau
+3  A: 

Even without swapping,that's caused by the "stupid" implementation of the Garbage Collector for Javascript in IE. It uses some heuristics that call the GC more often, if there are more objects.

There's not way you can avoid this, other than avoiding memory leaks like hell and also avoid creating too many Javascript objects.

Regards, Markus

kohlerm
Hi Ian,Is there a policy to not add a signature, or why did you remove it?
kohlerm
http://meta.stackoverflow.com/questions/28416/what-is-the-policy-on-signatures-and-links-in-answers
plodoc