[How-To] Detect memory leaks in Javascript
Many web developers often develop websites which results in memory leaks when viewing the websites in Internet Explorer. Most of these memory leaks often occur because of circular references between Javascript object and objects within IE’s DOM.
Both the JavaScript engine and IE have independent memory management schemes. The JavaScript engine uses garbage collection to reclaim the memory allocated for JavaScript objects that are not used anymore.
Instead, an IE DOM object is a COM object; therefore its lifespan is ruled by a reference count. Both systems work perfectly in isolation but problems can arise when there are circular references between these two worlds as each side can’t see the entire cycle of these references.
For example, the following code (used to) generate a leak in IE6:
<script type=”text/javascript”>
<!– var jsObject;
function SetupLeak()
{
jsObject = document.getElementById(“LeakedDiv”); document.getElementById(“LeakedDiv”).expandoProperty = jsObject;
} // –></script>
Here the SetupLeak() function creates a circular reference like this:
However, now debugging such memory leaks is easier to debug than before. JavaScript Memory Leak Detector (download) is a debugging tool to detect memory leaks in JavaScript code. It can be installed as an Internet Explorer band and it is expressly designed to find memory leaks in JavaScript code that runs in Internet Explorer.
Source: Microsoft Europe
Also read: Understanding HTTP Cookies
Batch Script for removing Internet Explorer 7 from your PC
[How-To]Save Keystrokes in Internet Explorer
Anti Spyware Applications: Here goes the ranking. :)
You can also follow me on Twitter at http://twitter.com/vaibhav1981
Do stay tuned to Technofriends for more, one of the best ways of doing so is by subscribing to our feeds. You can subscribe to Technofriends feed by clicking here.
Cheers
Vaibhav
Related posts:
- Recap of this week’s best posts
- What is Javascript and some must watch tutorial videos
- Memory Fox keeps an eye on Firefox’s Memory Usage
- How to get free available memory in Java program
- JavaScript Hijacking
