Hi Rob,
That is something of an extreme case, I'd expect that provided you
aren't constantly creating new objects and variables, it shouldn't be
an issue. I'm currently working on an intranet data entry, reporting
and workflow application with pages that will persist for some time,
hopefully not 2 weeks at a time!
Extreme, I don't know. With AJAX coming stronger and stronger, this case
will probably occur more in the future. But I agree that when we started
doing that, we found out that IE was totally not made for this kind of
things, and we had huge memory leaks.
(when you were using web services to update the page, and when the user
would refresh the page anyway using a full postback, we would lose up to
2MB memory each time!!) Also, the HTC component that Microsoft used to
ship to make using web services easier was also causing huge leaks.
In fact, one of IE's "security" updates last year was for us (Siemens),
in order to correct some of the problems we found out when doing this
kind of things. Also, the HTC component was marked "unsupported" about 2
weeks after we reported the problem, we take credit for that (should we
take credit for Atlas too? Nah, that's a bit too much ;-)
Which is better/worse is moot, but I take your point that memory
management should always be considered and if necessary, addressed.
My point was just that even though JavaScript is "only" a scripting
language, when using it intensively you risk the same problems than with
a "conventional" programming language.
Memory leaks in JavaScript *should* only be a product of a faulty
environment. If a script simply keeps adding more and more objects or
variables, it is plain poor coding that will cause problems
(eventually) in any language.
Client-side JavaScript has that particularity that you have to run it on
a platform that you didn't design (aka the web browser). In the web
browser, many memory leaks are caused when the HTML rendering engine,
the JavaScript engine and the CSS engine interact and risk creating
circular references. Such a circular reference cannot be garbage
collected even on a page refresh. That was actually our main issue
(especially with the HTC component, which encapsulates JavaScript and
references it with a CSS construct, making it damn easy to create this
kind of circular reference).
Absolutely. The first question is what is the benefit of the same
object having two properties synchronised to the same value? And is
whatever benefit is gained worth the overhead of managing the object's
properties manually?
I expect that discussion to be specific to a particular circumstance -
such as a page that is updated at 30 second intervals (via AJAX?) and
not refreshed for 2 weeks.
Well, in the beginning, IE would die in agony after less than one day.
Reaching 2 weeks was quite an achievement we're proud of ;-)
HTH,
Laurent